Hello,
I am trying to enable second-level cache (Ehcache) in Hibernate but without success.
My Spring configuration is as follows: <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.use_query_cache">true</prop> <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop> <prop key="hibernate.cache.provider_configuration_file_resource_path">ehcache.xml</prop>
My ehcache.xml file is: <?xml version="1.0" encoding="UTF-8"?> <ehcache> <diskStore path="c:\cache\"/> <defaultCache maxElementsInMemory="10000" eternal="false" timeToIdleSeconds="120" timeToLiveSeconds="120" overflowToDisk="true" maxElementsOnDisk="10000000" diskPersistent="false" diskExpiryThreadIntervalSeconds="120" memoryStoreEvictionPolicy="LRU" />
In my entity classes i use @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public class A implements java.io.Serializable {
I use Criteria API for loading data: Criteria criteria = session.createCriteria(A.class.getName()).setFirstResult(offset * maxResults).setMaxResults(maxResults); criteria.addOrder(Order.asc("id")); criteria.setCacheable(true); return criteria.list();
I checked cache statistics and in log i can see that: session.getSessionFactory().getStatistics().getSecondLevelCacheHitCount() is always 0! session.getSessionFactory().getStatistics().getSecondLevelCacheMissCount() is not 0 but varying and session.getSessionFactory().getStatistics().getSecondLevelCachePutCount() is constantly increasing.
Also i checked .data files in "c:\cache" and all files are empty.
Can someone help me about this, what i am missing?
Best regards.
|