com.nepxion.discovery.plugin.framework.cache.RuleCache Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discovery-plugin-framework-starter Show documentation
Show all versions of discovery-plugin-framework-starter Show documentation
Nepxion Discovery is a solution for Spring Cloud with blue green, gray, weight, limitation, circuit breaker, degrade, isolation, monitor, tracing, dye, failover, async agent
The newest version!
package com.nepxion.discovery.plugin.framework.cache;
/**
* Title: Nepxion Discovery
* Description: Nepxion Discovery
* Copyright: Copyright (c) 2017-2050
* Company: Nepxion
* @author Haojun Ren
* @version 1.0
*/
import java.util.concurrent.TimeUnit;
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.nepxion.discovery.common.entity.RuleEntity;
public class RuleCache {
private LoadingCache loadingCache;
public RuleCache() {
loadingCache = Caffeine.newBuilder()
.expireAfterWrite(365 * 100, TimeUnit.DAYS)
.initialCapacity(2)
.maximumSize(10)
.recordStats()
.build(new CacheLoader() {
@Override
public RuleEntity load(String key) throws Exception {
return null;
}
});
}
public boolean put(String key, RuleEntity ruleEntity) {
loadingCache.put(key, ruleEntity);
return Boolean.TRUE;
}
public RuleEntity get(String key) {
try {
return loadingCache.get(key);
} catch (Exception e) {
return null;
}
}
public boolean clear(String key) {
loadingCache.invalidate(key);
return Boolean.TRUE;
}
}