views:

193

answers:

1

Hello

I'm using ehcache with hibernate and I'd like to use the blocking or SelfPopulating cache to avoid the issues presented in http://ehcache.org/documentation/constructs-0_5.html#mozTocId722946

An expensive operation is required, say rendering a large web page, which takes 30 seconds. The page is not considered stale until it is 5 minutes old. The page is hit very heavily and will be hit an average of 20 times per minute each 5 minutes.

Do I have to do this programmatically as http://ehcache.org/documentation/cache_decorators.html suggests or is there a declarative (in xml) way to do so?

thanks a lot

+1  A: 

There is no way to do this in ehcache.xml since you must register the class with the CacheManager before the cache config is read.

So you must use the code mentioned in the docs and you must run this code before you do anything with Hibernate. A simple way to do this is to use the hibernate.cache.provider_class property which tells Hibernate a factory for the cache. Have a look at the source of an implementation which should give you an idea what you need to do.

Aaron Digulla
Thanks a lot for the insight. I'm already using SingletonEhCacheProvider and the implementation is final (I cannot extend it). Should I duplicate the code or would a custom servlet filter do the job?
cherouvim
You should duplicate the code.
Aaron Digulla