SingletonEhCacheRegionFactory vs EhCacheRegionFactory

Brad Cupit picture Brad Cupit · Jul 7, 2011 · Viewed 13.3k times · Source

This link (from the creator of Ehcache) says you should use SingletonEhCacheRegionFactory when you only have one Hibernate SessionFactory, and EhCacheRegionFactory when you have multiple.

But wouldn't EhCacheRegionFactory be a single instance anyway when you only have one SessionFactory?

So, what's better about SingletonEhCacheRegionFactory? Why not use EhCacheRegionFactory all the time since it can be used for one SessionFactory or multiple?

FYI: I'm using Ehcache 2.4.2 and Hibernate 3.6.5

Answer

Matej picture Matej · Oct 18, 2011

The non-singleton EhCacheRegionFactory allows you to configure EHCache separately for each Hibernate instance using net.sf.ehcache.configurationResourceName property. The SingletonEhCacheRegionFactory shares the same EHCache configuration among all Hibernate session factories.

EHCache documentation recommends to use the non-singleton version.

Edit: This information applies to EHCache 2.8. Not sure how many things have changed in the latest version.