1 package eu
.etaxonomy
.taxeditor
.remoting
.cache
;
3 import java
.io
.InputStream
;
4 import java
.util
.HashSet
;
7 import net
.sf
.ehcache
.Cache
;
8 import net
.sf
.ehcache
.CacheException
;
9 import net
.sf
.ehcache
.CacheManager
;
10 import net
.sf
.ehcache
.config
.CacheConfiguration
;
11 import net
.sf
.ehcache
.config
.SizeOfPolicyConfiguration
;
13 import org
.springframework
.core
.io
.ClassPathResource
;
14 import org
.springframework
.core
.io
.Resource
;
17 public class CdmRemoteCacheManager
{
19 private CacheManager cdmlibModelCacheManager
;
21 private static CdmRemoteCacheManager cdmRemoteCacheManager
= null;
23 private final Set
<CdmTransientEntityCacher
> transientEntityCachers
= new HashSet
<CdmTransientEntityCacher
>();
25 public static final Resource CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE
=
26 new ClassPathResource("cdmlib-ehcache.xml");
28 public static final String CDM_MODEL_CACHE_MGR_NAME
= "cdmlibModelCacheManager";
29 public static final String CDM_MODEL_CACHE_NAME
= "cdmModelGetMethodsCache";
32 public enum CdmCacheManagerType
{
37 public static CdmRemoteCacheManager
getInstance(){
38 if(cdmRemoteCacheManager
== null) {
39 cdmRemoteCacheManager
= new CdmRemoteCacheManager();
41 return cdmRemoteCacheManager
;
43 private CdmRemoteCacheManager() {
47 // NOTE:Programmatically creating the cache manager may solve the problem of
48 // recreating data written to disk on startup
49 // see https://stackoverflow.com/questions/1729605/ehcache-persist-to-disk-issues
50 //String cacheFilePath = CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE.getFile().getAbsolutePath();
51 InputStream in
= this.getClass().getClassLoader().getResourceAsStream("cdmlib-ehcache.xml");
53 SizeOfPolicyConfiguration sizeOfConfig
= new SizeOfPolicyConfiguration();
54 sizeOfConfig
.setMaxDepth(1000);
55 sizeOfConfig
.setMaxDepthExceededBehavior("abort");
57 CacheConfiguration modelcc
= new CacheConfiguration(CDM_MODEL_CACHE_NAME
, 0)
60 .sizeOfPolicy(sizeOfConfig
)
61 .overflowToOffHeap(false);
63 Cache modelCache
= new Cache(modelcc
);
65 cdmlibModelCacheManager
= CacheManager
.create(CDM_MODEL_CACHE_MGR_NAME
);
66 cdmlibModelCacheManager
.addCache(modelCache
);
68 } catch (CacheException e
) {
69 throw new CdmClientCacheException(e
);
74 public Cache
getCdmModelGetMethodsCache(){
75 return cdmlibModelCacheManager
.getCache(CDM_MODEL_CACHE_NAME
);
78 public CacheManager
getCdmModelGetMethodsCacheManager() {
79 return cdmlibModelCacheManager
;
82 public CacheManager
getDefaultCacheManager() {
83 return CacheManager
.create();
86 public void shutdown(CdmCacheManagerType ccmt
) {
90 cdmlibModelCacheManager
.shutdown();
93 cm
= CacheManager
.create();