当前位置:网站首页>Demo of guavacache
Demo of guavacache
2022-06-30 09:28:00 【Xiao Lu, a migrant worker in Beijing】
cache Interface
public interface Cache {
<T> T get(Object key, Class<T> type);
boolean has(Object key);
void put(Object key, Object value);
void del(Object key);
}cache factory
public class CacheFactory {
private static class GuavaCache implements Cache {
private org.springframework.cache.Cache cache;
GuavaCache(String cacheName, int expiredMinutes) {
cache = new ConcurrentMapCache(cacheName,
CacheBuilder.newBuilder()
.expireAfterWrite(expiredMinutes, TimeUnit.MINUTES)
.build().asMap(),
false);
}
GuavaCache(String cacheName, int expiredTime, TimeUnit timeUnit) {
cache = new ConcurrentMapCache(cacheName,
CacheBuilder.newBuilder()
.expireAfterWrite(expiredTime, timeUnit)
.build().asMap(),
false);
}
@Override
public <T> T get(Object key, Class<T> type) {
return cache.get(key, type);
}
@Override
public boolean has(Object key) {
return cache.get(key) != null;
}
@Override
public void put(Object key, Object value) {
cache.put(key, value);
}
@Override
public void del(Object key) {
cache.put(key,"");
}
}
static private final String PREFIX = "CACHE_FACTORY_";
static private int sn = 1;
synchronized static public Cache getCacheWithExpiredMinutes(int expiredMinutes) {
String cacheName = PREFIX + sn;
sn += 1;
return new GuavaCache(cacheName, expiredMinutes);
}
synchronized static public Cache getCacheWithExpiredSeconds(int expiredSeconds) {
String cacheName = PREFIX + sn;
sn += 1;
return new GuavaCache(cacheName, expiredSeconds, TimeUnit.SECONDS);
}
}Use
@Service
public class GuangPingDistributionDataHandler {
private Cache guangpingKeyWordListCache = CacheFactory.getCacheWithExpiredSeconds(10);
private static final String CACHEKEY = "guangpingCacheKey";
@Autowired
private DataToGuangPingAsynProducer dataToGuangPingAsynProducer;
@Autowired
private KeywordCommonRelationMapper keywordCommonRelationMapper;
@Override
Boolean isHitKeywords(List<String> keyWordList) {
List<String> giangPingKeyWordListFromCache = guangpingKeyWordListCache.get(CACHEKEY, List.class);
if (null == giangPingKeyWordListFromCache || giangPingKeyWordListFromCache.size() == 0) {
/** If there is no cache **/
List<String> giangPingKeyWordListFromDB = keywordCommonRelationMapper.selectKeyListByValue(String.valueOf(SystemSourceEnum.GUANGPING.getCode()));
giangPingKeyWordListFromCache = giangPingKeyWordListFromDB;
guangpingKeyWordListCache.put(CACHEKEY, giangPingKeyWordListFromDB);
}
for(String keyWord : keyWordList){
if(giangPingKeyWordListFromCache.contains(keyWord)){
return true;
}
}
return false;
}
}
边栏推荐
- 4. use ibinder interface flexibly for short-range communication
- Acquisition de 100% des actions de Guilin latex par Guilin Robust Medical pour combler le vide de la gamme de produits Latex
- ES6 learning road 5 symbol
- Niuke walks on the tree (ingenious application of parallel search)
- Esp32 (7): I2S and I2C drivers for function development
- Talking about the difference between kotlin collaboration and thread
- Interpretation of orientedrcnn papers
- Resnet50+fpn for mmdet line by line code interpretation
- Baidu map JS browsing terminal
- Solution to the sixth training competition of 2020 provincial competition
猜你喜欢

Baidu map JS browsing terminal

Bottomsheetbehavior principle of realizing the home page effect of Gaode map

Numpy (data type)

Talking about kotlin process exception handling mechanism

Opencv learning notes -day 12 (ROI region extraction and inrange() function operation)
![[shutter] solve failed assertion: line 5142 POS 12: '_ debugLocked‘: is not true.](/img/77/eb66ec83b34c251e732d495fbaa951.jpg)
[shutter] solve failed assertion: line 5142 POS 12: '_ debugLocked‘: is not true.

Opencv learning notes -day4 image pixel reading and writing operations (array traversal and pointer traversal implementation, uchar vec3b data type and mat class functions mat:: at(), mat:: ptr())

7. know JNI and NDK

Numpy (time date and time increment)

Rew acoustic test (VI): signal and measurement
随机推荐
Deep Learning with Pytorch- A 60 Minute Blitz
Niuke IOI weekly competition 20 popularization group (problem solving)
Talk about how the kotlin process started?
Metasploit practice - SSH brute force cracking process
Opencv learning notes-day9 opencv's own color table operation (colormap coloraptypes enumeration data types and applycolormap() pseudo color function)
Esp32 things (x): other functions
Deeply understand the working principle of kotlin collaboration suspend (beginners can also understand it)
Sort (simple description)
Talk about writing
ES6 learning path (IV) operator extension
Introduction to the runner of mmcv
Mysq database remote connection error, remote connection is not allowed
Interpretation of orientedrcnn papers
Design specification for smart speakers v1.0
Rew acoustic test (II): offline test
Terminal -- Zsh of terminal three swordsmen
Detailed explanation of pipline of mmdetection
Maxiouassigner of mmdet line by line interpretation
Advanced technology management -- how managers design and build echelons
Code management related issues