gpt4 book ai didi

javax.cache 自动删除条目

转载 作者:行者123 更新时间:2023-12-01 09:57:46 24 4
gpt4 key购买 nike

我有一个 javax.cache.Cache 实例,在 10 分钟不活动后,条目将被自动删除。无需深入探讨,是否有一个配置参数可以自动从缓存中删除键值对?

这是代码片段

@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);
}
}

最佳答案

这可能不是答案,但对于评论来说太长了。

您确实应该在问题中包含缓存 JNDI 配置。很难猜出你在做什么。但是,根据您提供的表面详细信息,我相信您可以尝试使用以下元素来控制缓存逐出和过期,如 Infinispan 子系统 documentation 中所述。 :

<eviction>

This child element configures the eviction behaviour of the cache.

  • strategy: This attribute configures the cache eviction strategy. Available options are UNORDERED, FIFO, LRU, LIRS and NONE (to disable eviction).

  • max-entries: This attribute configures the maximum number of entries in a cache instance. If selected value is not a power of two the actual value will default to the least power of two larger than selected value. -1 means no limit.

<expiration>

This child element configures the expiration behaviour of the cache.

  • max-idle: This attribute configures the maximum idle time a cache entry will be maintained in the cache, in milliseconds. If the idle time is exceeded, the entry will be expired cluster-wide. -1 means the entries never expire.

  • lifespan: This attribute configures the maximum lifespan of a cache entry, after which the entry is expired cluster-wide, in milliseconds. -1 means the entries never expire.

  • interval: This attribute specifies the interval (in ms) between subsequent runs to purge expired entries from memory and any cache stores. If you wish to disable the periodic eviction process altogether, set wakeupInterval to -1.

关于javax.cache 自动删除条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37045085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com