I am using Hibernate 2.1 with TreeCache & Spring. I have no problem using the 2nd level cache for the persistent objects (TreeCache) but right now I want to make use of the same cache "runtime" for caching of some non-persistent objects.
There are several reasons for this, the primary ones being that I want a central place for configuring the cache/cache regions (treecache.xml) and I don't want to have two TreeCache instances in the same VM (if I were to instantiate a new TreeCache object, that would be the case. Same case will in fact be forced if the non-persistent object cache that I talk about will take place in a different VM than hibernate's VM). I know that the discussion can get more complicated if one thinks about layering and horizontal decoupling but from the caching perspective I don't see a semantic difference between persistent/non persistent objects.
I have found an interesting article (
http://www.theserverside.com/articles/a ... ingWithAOP) but I still need to know whether is any way to obtain a reference to the current 2nd level cache provider object (I'm thinking of something similar to org.apache.log4j.Logger.getLogger(...) which will use the current logging context automagically). From there, I can use the net.sf.hibernate.cache.Cache interface to do cache manipulation.
Thanks,
florin