I'm having a problem with Hibernate's 2nd level cache using ehache. I'm doing some performance testing with multiple users and everything works fine for the first several minutes, but after that, there is a cache miss for some reason and then Hibernate does a N+1 select on the entire object graph that I'm trying to pull back, which is very painful.
I have ehcache set up pretty standard I think:
Code:
<defaultCache maxElementsInMemory="5000"
maxElementsOnDisk="20000" eternal="true" overflowToDisk="true"
memoryStoreEvictionPolicy="LRU" />
With the hibernate config:
Code:
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.use_second_level_cache"
value="true" />
and my entities and collections cached with the default provider:
Code:
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class MyClass extends BaseModel implements java.io.Serializable {
}
Everything works fine for awhile and they cache is being used, but then all of a sudden, without doing any system updates or inserts (reads only), ehcache says:
Code:
Memory cache hit, but element expired
and Hibernate pulls back all the graphs and collections N+1. We are using Hibernate 3.2 and ehcache 1.6.1. Increasing the size of the cache does no good. Any suggestions or ideas are appreciated.