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.  [ 1 post ] 
Author Message
 Post subject: 2nd level cache very slow compared to direct EHCache
PostPosted: Wed Nov 23, 2005 11:28 am 

Joined: Tue Nov 16, 2004 6:36 pm
Posts: 62
Location: Z├╝rich
Hibernate version: 3.1rc2


We used to cache some mappings from internal codes to texts, used intensively all over the application. Basically this cache was a direct global HashMap or a direct EHCache usage.

Now I got the idea to redo this using Hibernate 2nd level read-only cache (based on EHCache), but I was quite dissapointed with its performance.

Retrieving one object from the cache took 6 milliseconds(!), one such "code table" consists of one object and contains a Map and a List of a few hundred entries each. Also after querying these objects, we generate some lists, which are stored in an internal 3rd Map, which is not mapped to the database but only used for internal optimization.

Now I naively expected Hibernate to use the 2nd level cache to directly get and put the object from the underlying cache. However to my surprise, even for a simple read-only cache, Hibernate goes through all the usual assembly stuff (e.g. method assembleCacheEntry in class org.hibernate.event.def.DefaultLoadEventListener), kind of manually deserializing these immutable read-only cached objects. For a medium sized object with some collections, this takes an enormous amount of time, almost in the order of magnitute it would take to re-retrieve the object from the database :(.

For now, I'll have to stay away from the 2nd level cache for many purposes and continue to use my own application level caching (or using EHCache directly), but it is a pity of course.

Question: is there a reason that hibernate could not put Serializable objects directly in EHCache without all the overhead, especially for read-only cached objects?

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

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.