Revision 95b6f6f5
Added by Cherian Mathew almost 9 years ago
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmRemoteCacheManager.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.taxeditor.remoting.cache; |
2 | 2 |
|
3 |
import java.io.File; |
|
4 | 3 |
import java.io.InputStream; |
5 | 4 |
import java.util.HashSet; |
6 | 5 |
import java.util.Set; |
... | ... | |
8 | 7 |
import net.sf.ehcache.Cache; |
9 | 8 |
import net.sf.ehcache.CacheException; |
10 | 9 |
import net.sf.ehcache.CacheManager; |
10 |
import net.sf.ehcache.config.CacheConfiguration; |
|
11 |
import net.sf.ehcache.config.SizeOfPolicyConfiguration; |
|
11 | 12 |
|
12 | 13 |
import org.springframework.core.io.ClassPathResource; |
13 | 14 |
import org.springframework.core.io.Resource; |
14 | 15 |
|
15 |
import eu.etaxonomy.cdm.common.CdmUtils; |
|
16 |
|
|
17 | 16 |
|
18 | 17 |
public class CdmRemoteCacheManager { |
19 | 18 |
|
... | ... | |
26 | 25 |
public static final Resource CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE = |
27 | 26 |
new ClassPathResource("cdmlib-ehcache.xml"); |
28 | 27 |
|
28 |
public static final String CDM_MODEL_CACHE_MGR_NAME = "cdmlibModelCacheManager"; |
|
29 | 29 |
public static final String CDM_MODEL_CACHE_NAME = "cdmModelGetMethodsCache"; |
30 | 30 |
|
31 | 31 |
|
... | ... | |
42 | 42 |
} |
43 | 43 |
private CdmRemoteCacheManager() { |
44 | 44 |
|
45 |
System.setProperty("ehcache.disk.store.dir", CdmUtils.getCdmHomeDir().getAbsolutePath() + File.separator + "cdmlib-model"); |
|
45 |
|
|
46 | 46 |
try { |
47 | 47 |
// NOTE:Programmatically creating the cache manager may solve the problem of |
48 | 48 |
// recreating data written to disk on startup |
49 | 49 |
// see https://stackoverflow.com/questions/1729605/ehcache-persist-to-disk-issues |
50 | 50 |
//String cacheFilePath = CDMLIB_CACHE_MANAGER_CONFIG_RESOURCE.getFile().getAbsolutePath(); |
51 | 51 |
InputStream in = this.getClass().getClassLoader().getResourceAsStream("cdmlib-ehcache.xml"); |
52 |
cdmlibModelCacheManager = new CacheManager(in); |
|
52 |
|
|
53 |
SizeOfPolicyConfiguration sizeOfConfig = new SizeOfPolicyConfiguration(); |
|
54 |
sizeOfConfig.setMaxDepth(1000); |
|
55 |
sizeOfConfig.setMaxDepthExceededBehavior("abort"); |
|
56 |
|
|
57 |
CacheConfiguration modelcc = new CacheConfiguration(CDM_MODEL_CACHE_NAME, 0) |
|
58 |
.eternal(true) |
|
59 |
.statistics(true) |
|
60 |
.sizeOfPolicy(sizeOfConfig) |
|
61 |
.overflowToOffHeap(false); |
|
62 |
|
|
63 |
Cache modelCache = new Cache(modelcc); |
|
64 |
|
|
65 |
cdmlibModelCacheManager = CacheManager.create(CDM_MODEL_CACHE_MGR_NAME); |
|
66 |
cdmlibModelCacheManager.addCache(modelCache); |
|
53 | 67 |
|
54 | 68 |
} catch (CacheException e) { |
55 | 69 |
throw new CdmClientCacheException(e); |
56 | 70 |
} |
57 |
// } catch (IOException e) { |
|
58 |
// throw new CdmClientCacheException(e); |
|
59 |
// } |
|
71 |
|
|
60 | 72 |
} |
61 | 73 |
|
62 | 74 |
public Cache getCdmModelGetMethodsCache(){ |
... | ... | |
86 | 98 |
} |
87 | 99 |
} |
88 | 100 |
|
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"); |
|
93 |
} |
|
94 |
} |
|
95 | 101 |
|
96 | 102 |
|
97 | 103 |
} |
Also available in: Unified diff
CdmApplicationRemoteController : refactoring code to simplify application context loading and making it performant
CdmModelCacher : removed unused method
CdmRemoteCacheManager : moved cache from disk to memory
httpInvokerServiceClients : lazy initializing all service beans
remotingApplicationContext : merged imported bean definition files into this one
CdmApplicationRemoteControllerTest : test for application controller
RemotingMonitoredGenericApplicationContext, RemotingMonitoredListableBeanFactory : removed since specific monitoring is not required in remoting
remoting_persistence_security.xml, remoting_services_security.xml : merged into remotingApplicationContext