diff --git a/ContentGrabbingJi-CacheStore-local/src/main/java/net/lamgc/cgj/bot/cache/local/HashSetCacheStore.java b/ContentGrabbingJi-CacheStore-local/src/main/java/net/lamgc/cgj/bot/cache/local/HashSetCacheStore.java new file mode 100644 index 0000000..b59fe0e --- /dev/null +++ b/ContentGrabbingJi-CacheStore-local/src/main/java/net/lamgc/cgj/bot/cache/local/HashSetCacheStore.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2020 LamGC + * + * ContentGrabbingJi is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ContentGrabbingJi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.lamgc.cgj.bot.cache.local; + +import net.lamgc.cgj.bot.cache.SetCacheStore; + +import java.util.*; + +/** + * + * @param 元素类型. + * @author LamGC + */ +public class HashSetCacheStore extends LocalCollectionCacheStore> implements SetCacheStore { + + @Override + protected Set getCacheItemCollection(String key, boolean create) { + Map>> cacheMap = getCacheMap(); + if (!cacheMap.containsKey(key)) { + if (create) { + cacheMap.put(key, new CacheItem<>(new HashSet<>())); + } else { + return null; + } + } + return cacheMap.get(key).getValue(); + } + +} diff --git a/ContentGrabbingJi-CacheStore-local/src/main/java/net/lamgc/cgj/bot/cache/local/LocalCacheStoreFactory.java b/ContentGrabbingJi-CacheStore-local/src/main/java/net/lamgc/cgj/bot/cache/local/LocalCacheStoreFactory.java new file mode 100644 index 0000000..028e5a7 --- /dev/null +++ b/ContentGrabbingJi-CacheStore-local/src/main/java/net/lamgc/cgj/bot/cache/local/LocalCacheStoreFactory.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2020 LamGC + * + * ContentGrabbingJi is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * ContentGrabbingJi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package net.lamgc.cgj.bot.cache.local; + +import net.lamgc.cgj.bot.cache.*; +import net.lamgc.cgj.bot.cache.convert.StringConverter; + +/** + * 本地缓存存储容器工厂. + * 最快速但又是最占内存的方法, 适用于远端缓存失效, 或无远端缓存的情况下使用. + * 最简单的缓存实现, 无持久化功能. + * @author LamGC + */ +public class LocalCacheStoreFactory implements CacheStoreFactory { + + @Override + public SingleCacheStore newSingleCacheStore(String identify, StringConverter converter) { + return new HashSingleCacheStore<>(); + } + + @Override + public ListCacheStore newListCacheStore(String identify, StringConverter converter) { + return new CopyOnWriteArrayListCacheStore<>(); + } + + @Override + public SetCacheStore newSetCacheStore(String identify, StringConverter converter) { + return new HashSetCacheStore<>(); + } + + @Override + public MapCacheStore newMapCacheStore(String identify, StringConverter converter) { + return new HashMapCacheStore<>(); + } + +}