2017-05-08 45 views
0

有一個Spring/Tomcat應用程序,我試圖讓ehcache作爲Hibernate二級實體緩存工作。它已啓用並處於活動狀態。我可以在調試日誌輸出中看到有多少實體被緩存。問題是每隔幾秒鐘,緩存清空。我甚至固定緩存(只是爲了看看是否能夠改變行爲),現在我看到這個:休眠第二級緩存不斷清空

05-08-2017 16:05:21.550 [taskExecutor-12] {env=''} WARN n.s.e.Cache: Data availability impacted: 
**************************************************************************************** 
************************** removeAll called on a pinned cache ************************** 

05-08-2017 16:05:21.550 [taskExecutor-12] {env=''} WARN n.s.e.Cache: Data availability impacted: 
**************************************************************************************** 
************************** removeAll called on a pinned cache ************************** 

所以我覺得這是問題。任何想法會導致removeAll被一遍又一遍地隱式調用?

ehcache.xml中

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:noNamespaceSchemaLocation="ehcache.xsd" 
    updateCheck="true" 
    monitoring="autodetect" 
    maxBytesLocalHeap="24G" 
    dynamicConfig="true"> 

    <defaultCache eternal="true" maxBytesLocalHeap="1" /> <!-- not used, but required per ehcache configuration rules --> 

    <!-- cache for foo --> 
    <cache name="foo" 
      maxBytesLocalHeap="8G" 
      eternal="false" 
      memoryStoreEvictionPolicy="LRU" 
      timeToLiveSeconds="12000" 
      transactionalMode="off"> 
     <pinning store="inCache" /> 
     <persistence strategy="none" /> 
    </cache> 
</ehcache> 

的persistence.xml

 <properties> 
      <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> 
      <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" /> 
      <property name="hibernate.show_sql" value="false" /> 
      <property name="hibernate.hbm2ddl.auto" value="update" /> 
      <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.ImprovedNamingStrategy" /> 
      <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider" /> 
      <property name="hibernate.cache.use_second_level_cache" value="true" /> 
      <property name="hibernate.cache.use_query_cache" value="false" /> 
      <property name="hibernate.generate_statistics" value="true" /> 
      <property name="hibernate.cache.use_structured_entries" value="true" /> 
      <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory" /> 
     </properties> 

而且這些註釋是對實體模型類:

@Cacheable 
@Cache(region = "foo", usage = CacheConcurrencyStrategy.READ_WRITE) 

回答