-->
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.  [ 9 posts ] 
Author Message
 Post subject: clear cache
PostPosted: Sat May 07, 2005 7:03 pm 
Beginner
Beginner

Joined: Thu Mar 03, 2005 5:01 am
Posts: 33
Location: Wrocław (Poland)
hi,

I do an SessionFactory initioalization in init method of my servlet :

Code:
SessionFactory factory;

   public void init(ServletConfig config) throws ServletException {
      try {
         factory = new Configuration().configure("/hibernate.cfg.xml")
               .buildSessionFactory();

...



but sometimes I need to completly clear cache. How can I do it?

This is my sample function, but I don't see any changes in appliction memory usage after executing it :


Code:
         factory.close();
         factory = null;
         System.gc();         
         factory = new Configuration().configure("/hibernate.cfg.xml")
                  .buildSessionFactory();


thanks in advance!

_________________
bimki


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 08, 2005 1:04 pm 
Beginner
Beginner

Joined: Thu Mar 03, 2005 5:01 am
Posts: 33
Location: Wrocław (Poland)
In short - I need to have "cold" transaction start after some time without restarting tomcat :)

_________________
bimki


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 6:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
closing all sessions and the factory free the resources.
you can do sf.evict*() if you don't want to close it

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 7:01 am 
Beginner
Beginner

Joined: Thu Mar 03, 2005 5:01 am
Posts: 33
Location: Wrocław (Poland)
does just calling session.close clear the cache?

_________________
bimki


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 10:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Session.close() clears the session cache.

SessionFactory.close() calls the CacheProvider's stop() method. It is up to each CacheProvider what they want to do here, so it depends on which cache provider you are using.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 7:56 pm 
Beginner
Beginner

Joined: Thu Mar 03, 2005 5:01 am
Posts: 33
Location: Wrocław (Poland)
This is my new solution :

Code:
         factory.evictQueries();
         factory.close();
         factory = null;
         
         factory = new Configuration().configure("/hibernate.cfg.xml")
               .buildSessionFactory();


is after calling this code all the cache free?

Greetings

_________________
bimki


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 09, 2005 9:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
SessionFactory.close() calls the CacheProvider's stop() method. It is up to each CacheProvider what they want to do here, so it depends on which cache provider you are using.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 4:11 am 
Beginner
Beginner

Joined: Thu Mar 03, 2005 5:01 am
Posts: 33
Location: Wrocław (Poland)
I'm using org.hibernate.cache.HashtableCacheProvider.

_________________
bimki


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 10:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
With HashtableCacheProvider, references to the individual Maps are not maintained by the provider. So they are explicitly not cleared. However, on SessionFactory shutdown all references to them would get cleaned up and they would become eligible for garbage collection.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.