1 package eu
.etaxonomy
.taxeditor
.remoting
.cache
;
4 import java
.io
.InputStream
;
6 import net
.sf
.ehcache
.Cache
;
7 import net
.sf
.ehcache
.CacheException
;
8 import net
.sf
.ehcache
.CacheManager
;
10 import org
.springframework
.core
.io
.ClassPathResource
;
11 import org
.springframework
.core
.io
.Resource
;
13 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
16 public class CdmRemoteCacheManager
{
18 private CacheManager cdmlibModelCacheManager
;
20 private static CdmRemoteCacheManager cdmRemoteCacheManager
= null;
22 public static final Resource CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE
=
23 new ClassPathResource("cdmlib-ehcache.xml");
25 public static final String CDM_MODEL_CACHE_NAME
= "cdmModelGetMethodsCache";
28 public enum CdmCacheManagerType
{
33 public static CdmRemoteCacheManager
getInstance(){
34 if(cdmRemoteCacheManager
== null) {
35 cdmRemoteCacheManager
= new CdmRemoteCacheManager();
37 return cdmRemoteCacheManager
;
39 private CdmRemoteCacheManager() {
41 System
.setProperty("ehcache.disk.store.dir", CdmUtils
.getCdmHomeDir().getAbsolutePath() + File
.separator
+ "cdmlib-model");
43 // NOTE:Programmatically creating the cache manager may solve the problem of
44 // recreating data written to disk on startup
45 // see https://stackoverflow.com/questions/1729605/ehcache-persist-to-disk-issues
46 //String cacheFilePath = CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE.getFile().getAbsolutePath();
47 InputStream in
= this.getClass().getClassLoader().getResourceAsStream("cdmlib-ehcache.xml");
48 cdmlibModelCacheManager
= new CacheManager(in
);
50 } catch (CacheException e
) {
51 throw new CdmClientCacheException(e
);
53 // } catch (IOException e) {
54 // throw new CdmClientCacheException(e);
58 public Cache
getCdmModelGetMethodsCache(){
59 return cdmlibModelCacheManager
.getCache(CDM_MODEL_CACHE_NAME
);
62 public CacheManager
getCdmModelGetMethodsCacheManager() {
63 return cdmlibModelCacheManager
;
66 public CacheManager
getDefaultCacheManager() {
67 return CacheManager
.create();
70 public void shutdown(CdmCacheManagerType ccmt
) {
74 cdmlibModelCacheManager
.shutdown();
77 cm
= CacheManager
.create();
85 public static void checkCacheProperties() {
86 String pathToCache
= System
.getProperty("ehcache.disk.store.dir");
87 if(pathToCache
== null || pathToCache
.isEmpty()) {
88 throw new CdmClientCacheException("'ehcache.disk.store.dir' property is not set");