Expiration of StandardQueryCache in Hibernate

158 views
Skip to first unread message

gum...@gmail.com

unread,
May 14, 2014, 5:23:52 AM5/14/14
to haze...@googlegroups.com
I'm using Hazelcast(3.2.1) with Hibernate(3.6.10), Second Level Cache and Query Cache enabled.
It seems as if my StandardQueryCache never expires.

I tried to get to know what happens with the StandardQueryCache with the debugger and noticed the following:
At the construction of the LocalRegionCache (in HazelcastQueryResultsRegion) the HazelcastInstance is set to null which causes "config" also to be null.
Does that mean that whatever I write in the config about the expiration of the StandardQueryCache is ignored?

What would be the right way to assure that the query cache never blows up my memory?


Regards
Martin

Mehmet Dogan

unread,
May 16, 2014, 9:54:50 AM5/16/14
to haze...@googlegroups.com
Query cache is managed by Hibernate itself. Hibernate has a timestamp cache, containing a timestamp for each database table and whenever a table is updated, its timestamp is updated too. Each query entry in query cache also has a timestamp. And queries are evicted from query cache by Hibernate when table timestamps are greater than query timestamp. 

Mehmet Dogan
Developer
 
Mahir İz Cad. No:35, Altunizade, İstanbul 
meh...@hazelcast.com 
@mmdogan



--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/ba81f8cb-e754-4a1b-a97e-ecfd39c29218%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gum...@gmail.com

unread,
May 21, 2014, 7:12:39 AM5/21/14
to haze...@googlegroups.com
I made a Test (see below) to verify your proposition but in fact i couldn't even get a single case where the Querycache is evicted.
However if i have a lot of queries and no changes in a period of time, Querycache will constantly increase. Is there no meachanism to prevent that?


@Test
public void testQueryEviction() throws Exception {

Session session = null;
Transaction transaction = null;

// insert a TestEntity
session = SessionFactoryUtil.getInstance().openSession();
transaction = session.beginTransaction();

TestEntity testEntity = new TestEntity("first");
session.save(testEntity);

transaction.commit();
session.close();

// list all Test entities
session = SessionFactoryUtil.getInstance().openSession();
session.createCriteria(TestEntity.class).setCacheable(true).list();
session.close();

QueryCacheAccessor.printSize(); // should be 1    // Another nasty thing here: I cannot get the right statistics via HazelcastInstance.getMap("org.hibernate.cache.StandardQueryCache") this is why i have my own workaround here

// insert another TestEntity
session = SessionFactoryUtil.getInstance().openSession();
transaction = session.beginTransaction();

TestEntity secondTestEntity = new TestEntity("second");
session.save(secondTestEntity);

transaction.commit();
session.close();

Thread.sleep(5000); // give Hazelcast some time to cleanup cache

QueryCacheAccessor.printSize(); // should be 0 actually is 1
}
Reply all
Reply to author
Forward
0 new messages