-
1. Re: Best Practice to clear the caches
sannegrinovero Sep 28, 2010 6:22 AM (in response to matth)you mean when using Infinispan as a second level cache for Hibernate?
-
2. Re: Best Practice to clear the caches
matth Sep 28, 2010 8:16 AM (in response to sannegrinovero)yes, because I tried to clear the caches via the method of the sessionFactory instance but the cache behavior became very strange :/
-
3. Re: Best Practice to clear the caches
sannegrinovero Sep 29, 2010 8:47 AM (in response to matth)can you define "strange" ? It's hard to help with all this information.
-
4. Re: Best Practice to clear the caches
matth Sep 29, 2010 9:02 AM (in response to sannegrinovero)Actually when I clear my caches (2nd level + query cache), the first time a new query is executed, the request works as expected : the fetch entities are retrieved, and the query is put into cache, but the second time a query is executed it's strange : the query no longer appear (it has been put into cache) however the fetch entites are not retrieved, and as the matter of fact i have a lot of loads then... and it takes way too much timee :/
-
5. Re: Best Practice to clear the caches
sannegrinovero Sep 29, 2010 9:25 AM (in response to matth)are you having this problem just when using Infinispan or also when using other cache providers? Could you try the HashtableCacheProvider?
I suspect that you didn't flag the entities as cacheable, it's possible to cache the queries only or the entities only, or both.
-
6. Re: Best Practice to clear the caches
matth Sep 29, 2010 11:08 AM (in response to sannegrinovero)Thanks for your help Sann.
I've just tried with HashtableCacheProvider but i didn't manage to clear the caches. With Infinispan, I used the methods :
// collections Map<String, CollectionMetadata> roleMap = factory.getAllCollectionMetadata(); for (String roleName : roleMap.keySet()) { factory.getCache().evictCollectionRegion(roleName); } // entities Map<String, ClassMetadata> entityMap = factory.getAllClassMetadata(); for (String entityName : entityMap.keySet()) { factory.getCache().evictEntityRegion(entityName); } // query factory.getCache().evictDefaultQueryRegion(); factory.getCache().evictQueryRegion(UpdateTimestampsCache.REGION_NAME);
I don't know why they don't work with other cache providers...
-
7. Re: Best Practice to clear the caches
sannegrinovero Sep 30, 2010 5:37 PM (in response to matth)I've just tried with HashtableCacheProvider but i didn't manage to clear the caches.
Sorry I couldn't understand. You mean it doesn't work as expected with HashtableCacheProvider? In that case I doubt it's a problem with Infinispan.
-
8. Re: Best Practice to clear the caches
matth Oct 8, 2010 8:47 AM (in response to sannegrinovero)Hey,
Actually with HashtableCacheProvider, it's worse because I can't clear the caches with the standard methods I wrote above.
I have the feeling that clearing the caches is not a process often used as there is a lack of documentation about it.
Thanks for your help
-
9. Re: Best Practice to clear the caches
galder.zamarreno Oct 18, 2010 12:45 PM (in response to matth)Matthieu, I don't think this is the right place to ask this question. Hibernate gives you no chance to access the cache directly, so you can't get hold of the Infinispan cache instances from Hibernate. Instead, you should ask and search the Hibernate forum.
In the mean time, I see that Hibernate trunk has evictEntityRegions(), evictCollectionRegions() and evictQueryRegions() methods in Cache. Not sure if they're in any released version, but you should try to see if those work.