【发布时间】:2018-02-12 17:17:06
【问题描述】:
要求:缓存时,如果为缓存提供的最大堆大小超过,它应该溢出到磁盘并从那里获取它。 我的 ehcache 配置:
cache:
timeToLiveSeconds: 3600
ehcache:
maxBytesLocalHeap: 1M
setMaxBytesLocalDisk: 5G
diskStore: cacheDiskStore
这是 ehcache.xml 配置(被 yml 中提供的值覆盖):
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" name="CM1"
updateCheck="false" maxBytesLocalHeap="1M" maxBytesLocalDisk="1M" maxEntriesLocalDisk="100000">
<!-- This is a default configuration, it is re-configured by the CacheConfiguration
Spring Bean, using the properties from the resources/config/*.yml files. -->
<diskStore path="cacheDiskStore" />
<defaultCache eternal="false" overflowToDisk="true" />
<cache name="cache1" >
<persistence strategy="localTempSwap" />
</cache>
<cache name="cache2" >
<persistence strategy="localTempSwap" />
</cache>
我正在缓存大型媒体文件。但是当我尝试从缓存中检索元素时,它总是为空。这就是我从缓存中检索的方式:
Element elt = CacheManager.getInstance()
.getEhcache("<cacheName>").get(<key>);
if (elt != null) {
System.out.println("**** Retrieved from cache *****");
return elt;
} else {
System.out.println("**** NOT FOUND IN CACHE *****");
return null;
}
它不是从缓存中挑选的。 如果我增加缓存堆大小,它可以正常工作。有什么帮助吗?
【问题讨论】: