1 package eu
.etaxonomy
.taxeditor
.remoting
.cache
;
4 import java
.io
.InputStream
;
5 import java
.util
.HashSet
;
8 import net
.sf
.ehcache
.Cache
;
9 import net
.sf
.ehcache
.CacheException
;
10 import net
.sf
.ehcache
.CacheManager
;
12 import org
.springframework
.core
.io
.ClassPathResource
;
13 import org
.springframework
.core
.io
.Resource
;
15 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
18 public class CdmRemoteCacheManager
{
20 private CacheManager cdmlibModelCacheManager
;
22 private static CdmRemoteCacheManager cdmRemoteCacheManager
= null;
24 private final Set
<CdmTransientEntityCacher
> transientEntityCachers
= new HashSet
<CdmTransientEntityCacher
>();
26 public static final Resource CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE
=
27 new ClassPathResource("cdmlib-ehcache.xml");
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() {
45 System
.setProperty("ehcache.disk.store.dir", CdmUtils
.getCdmHomeDir().getAbsolutePath() + File
.separator
+ "cdmlib-model");
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");
52 cdmlibModelCacheManager
= new CacheManager(in
);
54 } catch (CacheException e
) {
55 throw new CdmClientCacheException(e
);
57 // } catch (IOException e) {
58 // throw new CdmClientCacheException(e);
62 public Cache
getCdmModelGetMethodsCache(){
63 return cdmlibModelCacheManager
.getCache(CDM_MODEL_CACHE_NAME
);
66 public CacheManager
getCdmModelGetMethodsCacheManager() {
67 return cdmlibModelCacheManager
;
70 public CacheManager
getDefaultCacheManager() {
71 return CacheManager
.create();
74 public void shutdown(CdmCacheManagerType ccmt
) {
78 cdmlibModelCacheManager
.shutdown();
81 cm
= CacheManager
.create();
89 public static void checkCacheProperties() {
90 String pathToCache
= System
.getProperty("ehcache.disk.store.dir");
91 if(pathToCache
== null || pathToCache
.isEmpty()) {
92 throw new CdmClientCacheException("'ehcache.disk.store.dir' property is not set");