我只想将元素缓存在磁盘存储中,而不是内存/RAM 中,为此我使用了以下配置,它将元素存储在磁盘上,但 5 分钟后不会过期/从磁盘中删除数据。
<diskStore path="/global-cache" />
<cache name="globalCache"
maxElementsInMemory="0"
eternal="true"
timeToIdleSeconds="0"
diskSpoolBufferSizeMB="1"
diskPersistent="true"
timeToLiveSeconds="300"
diskExpiryThreadIntervalSeconds="120"
overflowToDisk="true"
memoryStoreEvictionPolicy="LFU" />
我可以在 ehcache 配置中做什么,以使磁盘存储中的元素在指定时间后过期?
最佳答案
你不能,如 documentation状态:
If an entry expires but is not accessed, and no resource constraints force eviction, then the expired entry remains in place.
即使某些约束会强制驱逐,Ehcache 也可能只删除部分过期条目,这样它就不需要扫描所有磁盘存储。 如果您绝对需要跟踪每个过期的条目,您将必须自己实现此功能,但这会影响您的性能。可能这就是 Ehcache 中未内置此功能的原因。
关于java - ehcache 磁盘存储中的元素不会过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24822345/