Hibernate version: 3.1rc2
Hello,
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?
[/b]
|