【发布时间】:2016-08-30 21:59:01
【问题描述】:
我有一个 javax.cache.Cache 实例,在 10 分钟不活动后,条目将被自动删除。不深入,有没有配置参数自动从缓存中移除键值对?
这里的代码是sn-p
@Produces
@FileRicAdapterService
public EventCacheFile getNamedEventsCache(InjectionPoint injectionPoint) {
Cache<String, CachedRecord> cache = getPersistentCacheManager()
.getCache("filetoric");
return new EventCacheFileImpl(cache);
}
@Produces
public CacheManager getPersistentCacheManager() {
return new CacheManagerAdapter(
getCacheContainer(Constants.PERSISTENT_CACHE));
}
private EmbeddedCacheManager getCacheContainer(String name) {
String jndiName = "java:jboss/infinispan/container/" + name;
try {
return (EmbeddedCacheManager) new InitialContext().lookup(jndiName);
} catch (NamingException e) {
logger.fatal("Cache container not found: %s", name);
throw new UnsatisfiedResolutionException(
"Cache container not found " + name);
}
}
【问题讨论】:
-
请在您声明缓存的地方发布代码。也请检查this answer
-
在配置中查找过期策略
标签: java jakarta-ee caching