Java 休眠二级缓存ehcache timeToLive to short
我为spring应用程序中的一些实体配置了带有ehcache的二级hibernate缓存 缓存应该能生存10分钟,但缓存的实体似乎活不了那么久 我的实体看起来是这样的:Java 休眠二级缓存ehcache timeToLive to short,java,spring,hibernate,ehcache,Java,Spring,Hibernate,Ehcache,我为spring应用程序中的一些实体配置了带有ehcache的二级hibernate缓存 缓存应该能生存10分钟,但缓存的实体似乎活不了那么久 我的实体看起来是这样的: @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "eh_apples") public class Apple { ... @Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "eh_apples")
public class Apple {
...
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE, region = "eh_eaters")
@ManyToMany(fetch = FetchType.EAGER)
private Set<AppleEater> eaters = new HashSet<AppleEater>();
....
}
我的第一个猜测是,您将到达maxEntriesLocalHeap或maxBytesLocalHeap,这将导致逐出 您可以通过查看统计数据来确认这一点。问题是:
net.sf.ehcache.config.ConfigurationFactory-未找到任何配置。
从ehcache-failsafe.xml配置ehcache
解决方案是,将ehcache从META-INF
移动到src/main/resources
:
你有persistence.xml中的所有内容吗?没有,我读过关于此选项的文章,但我不完全理解它的好处。据我所知,所有内容都将使我的所有实体都可缓存。但是我不是已经有缓存实体了吗?只要我愿意,它们就不会被缓存:/yeah..您使用的是哪台服务器?在windows上本地:pivotal tc server v3.2或Tomcat v8.0我使用统计数据运行了一个测试,并将结果添加到问题中。它们的尺寸非常小,永远不会达到给定的限制,所以它们不会被驱逐。2分钟后过期。
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_minimal_puts" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
<property name="hibernate.cache.provider_configuration_file_resource_path" value="META-INF/ehcache.xml"/>
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.EhCacheRegionFactory"></property>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ehcache.xsd"
updateCheck="true"
monitoring="autodetect"
dynamicConfig="true"
maxBytesLocalHeap="500M">
<diskStore path="java.io.tmpdir/ehcache" />
<cache
name="eh_apples"
eternal="false"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"
timeToLiveSeconds="600">
<persistence strategy="localTempSwap" />
</cache>
<cache
name="eh_eaters"
eternal="false"
overflowToDisk="false"
memoryStoreEvictionPolicy="LRU"
timeToLiveSeconds="600">
<persistence strategy="localTempSwap" />
</cache>
<cache
name="org.hibernate.cache.internal.StandardQueryCache"
eternal="false"
timeToLiveSeconds="600">
<persistence strategy="localTempSwap" />
</cache>
<cache
name="org.hibernate.cache.spi.UpdateTimestampsCache"
eternal="true">
<persistence strategy="localTempSwap" />
</cache>
</ehcache>
2017-03-04 10:45:54,563 [tomcat-http--90] WARN net.sf.ehcache.config.ConfigurationFactory - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/repo/sts-bundle/pivotal-tc-server-developer-3.2.2.RELEASE/base-instance/wtpwebapps/Apples/WEB-INF/lib/ehcache-2.10.2.2.21.jar!/ehcache-failsafe.xml