Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SingletonEhCacheRegionFactory vs EhCacheRegionFactory

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

like image 906
Brad Cupit Avatar asked Jul 07 '11 19:07

Brad Cupit


1 Answers

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.

like image 117
Matej Avatar answered Sep 20 '22 03:09

Matej