Commit 9584be5a authored by LAVENIER's avatar LAVENIER
Browse files

[fix] Cache: make sure to start modules cache config, when cache manager exists

parent fef483a5
......@@ -22,6 +22,7 @@
package net.sumaris.core.extraction.cache;
import net.sf.ehcache.CacheManager;
import net.sumaris.core.dao.cache.CacheConfiguration;
import net.sumaris.core.dao.technical.ehcache.Caches;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -32,7 +33,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnBean({org.springframework.cache.CacheManager.class})
@ConditionalOnBean({CacheConfiguration.class})
public class ExtractionCacheConfiguration {
/**
* Logger.
......@@ -40,9 +41,14 @@ public class ExtractionCacheConfiguration {
protected static final Logger log =
LoggerFactory.getLogger(ExtractionCacheConfiguration.class);
@Autowired
protected CacheManager cacheManager;
@Autowired
protected ExtractionCacheConfiguration(CacheConfiguration cacheConfiguration) {
this.cacheManager = cacheConfiguration.getCacheManager();
log.info("Adding Extraction caches...");
}
@Bean
public EhCacheFactoryBean aggregationTypeById() {
return Caches.createHeapCache(cacheManager, ExtractionCacheNames.AGGREGATION_TYPE_BY_ID, 1500, 1500, 100);
......
......@@ -22,6 +22,7 @@
package net.sumaris.rdf.cache;
import net.sf.ehcache.CacheManager;
import net.sumaris.core.dao.cache.CacheConfiguration;
import net.sumaris.core.dao.technical.ehcache.Caches;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -32,7 +33,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnBean({org.springframework.cache.CacheManager.class})
@ConditionalOnBean({CacheConfiguration.class})
public class RdfCacheConfiguration {
/**
* Logger.
......@@ -40,9 +41,14 @@ public class RdfCacheConfiguration {
protected static final Logger log =
LoggerFactory.getLogger(RdfCacheConfiguration.class);
@Autowired
protected CacheManager cacheManager;
@Autowired
protected RdfCacheConfiguration(CacheConfiguration cacheConfiguration) {
this.cacheManager = cacheConfiguration.getCacheManager();
log.info("Adding RDF caches...");
}
@Bean
public EhCacheFactoryBean ontologyByNameCache() {
return Caches.createHeapCache(cacheManager, RdfCacheNames.ONTOLOGY_BY_NAME, 1500, 1500, 600);
......
......@@ -51,10 +51,12 @@ public class CacheConfiguration {
@PostConstruct
protected void init() {
if (this.cacheManager == null) {
log.info("Starting cache manager...");
this.cacheManager = ehcache();
}
log.info("Starting cache manager...");
if (this.cacheManager == null) this.cacheManager = ehcache();
}
public CacheManager getCacheManager() {
return this.cacheManager;
}
@Bean(name="ehcacheFactory")
......@@ -190,10 +192,9 @@ public class CacheConfiguration {
return Caches.createHeapCache(ehcache(), CacheNames.TABLE_META_BY_NAME, CacheDurations.DEFAULT, CacheDurations.DEFAULT, 500);
}
/* -- protected methods -- */
/* protected */
protected CacheManager ehcache() {
return cacheManager != null ? cacheManager : ehcacheFactory().getObject();
return (cacheManager != null) ? cacheManager : ehcacheFactory().getObject();
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment