My problem : How to evict 2nd level cached queries?
Technology used so far: Spring 3.2 framework with JPA 2.0 and hibernate 3.2.
I am having following properties defined in my persistence.xml:
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
So far we don't have a direct dependency on Hibernate anywhere in our code other than this.
query.setHint("org.hibernate.cacheable", true);
Coming back to the problem:
I have implemented 2nd level Query caching for a complex query( 6-7 table joins and some conditions).
The good thing is that data in all these tables are less likely to change and since same data is getting fired for each user,this is the perfect query to be cached.
However, if data in any one of the underlying tables gets updated, the cache needs to be evicted. JPA EntityManagerProvider provides two methods
emf.getCache().evictAll();
emf.getCache().evict();
I cann't use evictAll() as I believe it will clear all the cache for the application.
And evict() seems to be used for only evicting the cache from particular Entity not Queries.
So please provide me an optimum solution.