2

我对 Ehcache 配置有很大的问题。

我用:

  • ehcache 2.6.2
  • 休眠 3.3.1 GA

我当前的配置是下一个:

1) 休眠

<bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> 
  <property name="properties">
    <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> 
       <prop key="hibernate.default_schema">@db.schema@</prop> 
       <prop key="hibernate.show_sql">false</prop> 
       <prop key="connection.pool_size">10</prop> 
       <prop key="hibernate.jdbc.batch_size">30</prop> 
       <prop key="hibernate.default_batch_fetch_size">30</prop> 
       <prop key="hibernate.max_fetch_depth">30</prop> 
       <prop key="hibernate.cache.use_second_level_cache">true</prop> 
       <prop key="hibernate.cache.use_query_cache">true</prop> 
       <prop key="hibernate.cache.region.factory_class"> 
          net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory 
       </prop> 
       <prop key="net.sf.ehcache.configurationResourceName"> 
         /ehcache-config.xml 
       </prop> 
       <prop key="hibernate.generate_statistics">true</prop> 
     </props> 
  </property> 
</bean> 

2) ehcache-config.xml

<ehcache name="xxxx"> 

<diskStore path="java.io.tmpdir"/> 

<defaultCache 
  maxElementsInMemory="10000" 
  eternal="false" 
  timeToIdleSeconds="120" 
  timeToLiveSeconds="120" 
  overflowToDisk="true" 
  maxElementsOnDisk="10000000" 
  diskPersistent="false" 
  diskExpiryThreadIntervalSeconds="120" 
  memoryStoreEvictionPolicy="LRU" 
 /> 

 <cache name="org.hibernate.cache.UpdateTimestampsCache" 
   maxEntriesLocalHeap="5000" 
   eternal="true"> 
   <persistence strategy="localTempSwap"/> 
 </cache> 

 <cache name="org.hibernate.cache.StandardQueryCache" 
   maxElementsInMemory="10000" 
   eternal="false" 
   timeToIdleSeconds="120" 
   timeToLiveSeconds="120" 
   overflowToDisk="false" 
   diskExpiryThreadIntervalSeconds="120"> 
   <persistence strategy="localTempSwap"/> 
 </cache> 

 </ehcache> 

所有 java 对象都实现了 Serializable 并且我使用读写缓存,所有查询都是 setCacheable(true),但我仍然看不到性能改进。

首先,我有很多这样的消息:

 19:30:51,829 DEBUG [Segment] fault added 0 on disk 
 19:30:51,829 DEBUG [Segment] put added 0 on heap 
 19:30:51,829 DEBUG [Segment] fault removed 0 from heap 
 19:30:51,829 DEBUG [Segment] fault added 0 on disk 
 19:30:51,829 DEBUG [Segment] put added 0 on heap 
 19:30:51,830 DEBUG [Segment] fault removed 0 from heap 
 19:30:51,830 DEBUG [Segment] fault added 0 on disk 

我注意到的最重要的事情:所有使用缓存的尝试都以:

 1) 19:30:47,396 DEBUG [EhcacheGeneralDataRegion] Element for key sql: **** is null

 2) 20:26:31,939 DEBUG [EhcacheGeneralDataRegion] key: ****
    20:26:31,939 DEBUG [EhcacheGeneralDataRegion] Element for key **** is null 

谢谢您的帮助。

此致。

4

0 回答 0