-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: How evict all ehcache?
PostPosted: Wed Oct 26, 2005 12:03 pm 
Newbie

Joined: Mon Apr 11, 2005 6:59 am
Posts: 11
Hibernate version:3.05

Hi,
Hibernate 3 have the evictEntity(String entityName) to evict all entries from the second-level cache. I want to make a servlet for evict all the second-level cache dynamically (Reset)?

How make this? Please give me yours suggestions.

Thank you.


João


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 26, 2005 12:09 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
I believe you want to use Session.clear()


Top
 Profile  
 
 Post subject: Re:
PostPosted: Thu Feb 11, 2010 12:30 pm 
Newbie

Joined: Tue Jul 08, 2008 8:02 am
Posts: 10
dennisbyrne wrote:
I believe you want to use Session.clear()


No, I really want to evict entries from the second-level cache to force Hibernate to pick up changes made by direct writes to the database. For me it is no problem to evict all classes, as I have enumeration of all classes in the runtime. But I don't understand the warning in the documentation:

"Evict all entries from the second-level cache. This method occurs outside of any transaction; it performs an immediate "hard" remove, so does not respect any transaction isolation semantics of the usage strategy. Use with care."

What should I be aware of?


Top
 Profile  
 
 Post subject: Re: How evict all ehcache?
PostPosted: Thu Feb 11, 2010 3:31 pm 
Newbie

Joined: Thu Feb 11, 2010 9:25 am
Posts: 4
Hi jbrites,
I use this fragment for full eviction between unit tests.

Code:
      Map<String, CollectionMetadata> allCollectionMetadata = sessionFactory.getAllCollectionMetadata();
      for (String name : allCollectionMetadata.keySet()) {
         sessionFactory.evictCollection(name);
      }
      Map<String, CollectionMetadata> allClassMetadata = sessionFactory.getAllClassMetadata();
      for (String name : allClassMetadata.keySet()) {
         sessionFactory.evictEntity(name);
      }
      sessionFactory.evictQueries();


The warning in the docs is about isolation (the I in ACID): in same cases it could be possible for your application to "notice" the eviction, so that a first lookup returns the value from the cache, while a second one could return another one or change tha values of the previous instance or have problems with locking version numbers, etc. (I do not know which case is actually possible and when). In other words eviction is NOT transactional so queries results could change in different invocations and so on.
I think the session cache (first level cache) mitigate this risk but something could slip through (especially with queries).

If you have very strong transactional requirements do not do this (and do not use EhChace, BTW). Otherwise this should not be a big problem, unless you do something like to schedule an evict every N minutes to fetch data written from an external process. In this last case I expect the risk to be higher.

I think a more correct approach for cache refresh should be to issue some big queries with CacheMode.REFRESH to refresh the data (maybe fetching more data than the maximum size of the cache...). I suppose, but not for sure, this should be 100% safe if you are using a transactional cache like JBoss Cache.


Top
 Profile  
 
 Post subject: Re: How evict all ehcache?
PostPosted: Fri Feb 12, 2010 4:39 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
I think the session cache (first level cache) mitigate this risk


I really hope so.

Quote:
but something could slip through (especially with queries).


I wonder if there are really concrete scenarios where this happens. (I would be interesting to know more about such scenarios.)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.