1 package eu
.etaxonomy
.cdm
.api
.cache
;
5 import net
.sf
.ehcache
.config
.CacheConfiguration
;
6 import net
.sf
.ehcache
.config
.SizeOfPolicyConfiguration
;
8 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
9 import org
.springframework
.stereotype
.Component
;
11 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
12 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
13 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
14 import eu
.etaxonomy
.taxeditor
.remoting
.cache
.CacheLoader
;
15 import eu
.etaxonomy
.taxeditor
.remoting
.cache
.CdmTransientEntityCacher
;
16 import eu
.etaxonomy
.taxeditor
.service
.TermServiceRequestExecutor
;
19 * Class which uses CDM services to cache cdm entities
21 * FIXME: Currently only handles terms entities. It would be
22 * interesting to have a generic method which finds the
23 * correct service to load / cache the entity.
30 public class CdmServiceCacher
extends CdmCacher
{
33 ITermService termService
;
35 private CacheLoader cacheLoader
;
38 protected void setup() {
39 DefinedTermBase
.setCacher(this);
40 CdmTransientEntityCacher
.setDefaultCacher(this);
41 TermServiceRequestExecutor
.setDefaultCacher(this);
42 cacheLoader
= new CacheLoader(this);
46 protected CacheConfiguration
getDefaultCacheConfiguration() {
47 // For a better understanding on how to size caches, refer to
48 // http://ehcache.org/documentation/configuration/cache-size
50 SizeOfPolicyConfiguration sizeOfConfig
= new SizeOfPolicyConfiguration();
51 sizeOfConfig
.setMaxDepth(100);
52 sizeOfConfig
.setMaxDepthExceededBehavior("abort");
54 return new CacheConfiguration(DEFAULT_CACHE_NAME
, 0)
57 .sizeOfPolicy(sizeOfConfig
)
58 .overflowToOffHeap(false);
63 protected CdmBase
findByUuid(UUID uuid
) {
64 CdmBase term
= termService
.findWithoutFlush(uuid
);
69 * @see eu.etaxonomy.cdm.model.ICdmCacher#isCachable(eu.etaxonomy.cdm.model.common.CdmBase)
72 public boolean isCachable(CdmBase cdmEntity
) {
73 if(cdmEntity
!= null && cdmEntity
instanceof DefinedTermBase
) {
81 * @see eu.etaxonomy.cdm.api.cache.CdmCacher#load(eu.etaxonomy.cdm.model.common.CdmBase)
84 public CdmBase
load(CdmBase cdmEntity
) {
85 CdmBase cachedCdmEntity
= getFromCache(cdmEntity
);
86 // NOTE : only when no cached cdm entity exists we
87 // load the entire sub-graph, which means that the
88 // sub-graph is never updated if the input
89 // cdm entity graph is newer
90 if(cachedCdmEntity
== null && isCachable(cdmEntity
)) {
91 cachedCdmEntity
= cacheLoader
.load(cdmEntity
, true, false);
93 return cachedCdmEntity
;