use of net.sf.ehcache.CacheManager in project trainning by fernandotomasio.
the class OrganizationalCacheAdvice method findOrganizacaoMethodInterceptor.
@Around("findOrganizacao()")
public Object findOrganizacaoMethodInterceptor(ProceedingJoinPoint joinPoint) throws Throwable {
Object result = null;
CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
Cache cache = cacheManager.getCache("organizacoes-cache");
Object[] args = joinPoint.getArgs();
Long organizacaoId = (Long) args[0];
Element element = cache.get(organizacaoId);
if (element == null) {
result = joinPoint.proceed();
cache.put(new Element(organizacaoId, result));
} else {
Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Dados presentes no cache de organizações, não foi necessário acesso ao banco de dados");
result = element.getValue();
}
return result;
}
use of net.sf.ehcache.CacheManager in project trainning by fernandotomasio.
the class TesteEcache method main.
public static void main(String[] args) throws IOException, DAOException {
CacheManager cacheManager = CacheManager.create(new ClassPathResource("echache.xml").getInputStream());
TreinamentoSolicitadoDAO dao = new HibernateTreinamentoSolicitadoDAO();
List<TreinamentoSolicitadoDTO> list = dao.findAll(null, null, null, null);
System.out.println(list.size());
Cache cache = cacheManager.getCache("colecoesCache");
cache.put(new Element("treinamentosSolicitados", list));
Element e = cache.get("treinamentosSolicitados");
@SuppressWarnings("unchecked") List<TreinamentoSolicitadoDTO> recuperados = (List<TreinamentoSolicitadoDTO>) e.getValue();
for (TreinamentoSolicitadoDTO treinamentoSolicitadoDTO : recuperados) {
System.out.println(treinamentoSolicitadoDTO.getId());
}
}
use of net.sf.ehcache.CacheManager in project Gemma by PavlidisLab.
the class CacheKey method afterPropertiesSet.
@Override
public void afterPropertiesSet() {
CacheManager cacheManager = cacheManagerFactory.getObject();
int maxElements = Settings.getInt("gemma.cache.diffex.maxelements", DifferentialExpressionResultCacheImpl.CACHE_DEFAULT_MAX_ELEMENTS);
int timeToLive = Settings.getInt("gemma.cache.diffex.timetolive", DifferentialExpressionResultCacheImpl.CACHE_DEFAULT_TIME_TO_LIVE);
int timeToIdle = Settings.getInt("gemma.cache.diffex.timetoidle", DifferentialExpressionResultCacheImpl.CACHE_DEFAULT_TIME_TO_IDLE);
boolean eternal = Settings.getBoolean("gemma.cache.diffex.eternal", DifferentialExpressionResultCacheImpl.CACHE_DEFAULT_ETERNAL) && timeToLive == 0;
boolean terracottaEnabled = Settings.getBoolean("gemma.cache.clustered", true);
boolean overFlowToDisk = Settings.getBoolean("gemma.cache.diffex.usedisk", DifferentialExpressionResultCacheImpl.CACHE_DEFAULT_OVERFLOW_TO_DISK);
boolean diskPersistent = Settings.getBoolean("gemma.cache.diskpersistent", false) && !terracottaEnabled;
if (!cacheManager.cacheExists(DifferentialExpressionResultCacheImpl.CACHE_NAME_BASE)) {
/*
* See TerracottaConfiguration.
*/
int diskExpiryThreadIntervalSeconds = 600;
int maxElementsOnDisk = 10000;
boolean terracottaCoherentReads = false;
boolean clearOnFlush = false;
if (terracottaEnabled) {
CacheConfiguration config = new CacheConfiguration(DifferentialExpressionResultCacheImpl.CACHE_NAME_BASE, maxElements);
config.setStatistics(false);
config.setMemoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU.toString());
config.addPersistence(new PersistenceConfiguration().strategy(Strategy.NONE));
config.setEternal(eternal);
config.setTimeToIdleSeconds(timeToIdle);
config.setMaxElementsOnDisk(maxElementsOnDisk);
config.addTerracotta(new TerracottaConfiguration());
// noinspection ConstantConditions // Better readability
config.getTerracottaConfiguration().setCoherentReads(terracottaCoherentReads);
// noinspection ConstantConditions // Better readability
config.clearOnFlush(clearOnFlush);
config.setTimeToLiveSeconds(timeToLive);
config.getTerracottaConfiguration().setClustered(true);
config.getTerracottaConfiguration().setValueMode("SERIALIZATION");
NonstopConfiguration nonstopConfiguration = new NonstopConfiguration();
TimeoutBehaviorConfiguration tobc = new TimeoutBehaviorConfiguration();
tobc.setType(TimeoutBehaviorType.NOOP.getTypeName());
nonstopConfiguration.addTimeoutBehavior(tobc);
config.getTerracottaConfiguration().addNonstop(nonstopConfiguration);
this.cache = new Cache(config);
this.topHitsCache = new Cache(config);
this.topHitsCache.setName(DifferentialExpressionResultCacheImpl.TOP_HIT_CACHE_NAME_BASE);
} else {
this.cache = new Cache(DifferentialExpressionResultCacheImpl.CACHE_NAME_BASE, maxElements, MemoryStoreEvictionPolicy.LRU, overFlowToDisk, null, eternal, timeToLive, timeToIdle, diskPersistent, diskExpiryThreadIntervalSeconds, null);
this.topHitsCache = new Cache(DifferentialExpressionResultCacheImpl.TOP_HIT_CACHE_NAME_BASE, maxElements, MemoryStoreEvictionPolicy.LRU, overFlowToDisk, null, eternal, timeToLive, timeToIdle, diskPersistent, diskExpiryThreadIntervalSeconds, null);
}
cacheManager.addCache(cache);
cacheManager.addCache(topHitsCache);
}
}
use of net.sf.ehcache.CacheManager in project Gemma by PavlidisLab.
the class CoexpressionCacheImpl method afterPropertiesSet.
/**
* Initialize the cache; if it already exists it will not be recreated.
*/
@Override
public void afterPropertiesSet() {
CacheManager cacheManager = cacheManagerFactory.getObject();
assert cacheManager != null;
int maxElements = Settings.getInt("gemma.cache.gene2gene.maxelements", CoexpressionCacheImpl.GENE_COEXPRESSION_CACHE_DEFAULT_MAX_ELEMENTS);
int timeToLive = Settings.getInt("gemma.cache.gene2gene.timetolive", CoexpressionCacheImpl.GENE_COEXPRESSION_CACHE_DEFAULT_TIME_TO_LIVE);
int timeToIdle = Settings.getInt("gemma.cache.gene2gene.timetoidle", CoexpressionCacheImpl.GENE_COEXPRESSION_CACHE_DEFAULT_TIME_TO_IDLE);
boolean overFlowToDisk = Settings.getBoolean("gemma.cache.gene2gene.usedisk", CoexpressionCacheImpl.GENE_COEXPRESSION_CACHE_DEFAULT_OVERFLOW_TO_DISK);
boolean eternal = Settings.getBoolean("gemma.cache.gene2gene.eternal", CoexpressionCacheImpl.GENE_COEXPRESSION_CACHE_DEFAULT_ETERNAL) && timeToLive == 0;
boolean terracottaEnabled = Settings.getBoolean("gemma.cache.clustered", false);
boolean diskPersistent = Settings.getBoolean("gemma.cache.diskpersistent", false) && !terracottaEnabled;
this.cache = CacheUtils.createOrLoadCache(cacheManager, CoexpressionCacheImpl.GENE_COEXPRESSION_CACHE_NAME, terracottaEnabled, maxElements, overFlowToDisk, eternal, timeToIdle, timeToLive, diskPersistent);
}
use of net.sf.ehcache.CacheManager in project openmrs-core by openmrs.
the class OpenmrsCacheManagerFactoryBean method getObject.
@Override
public CacheManager getObject() {
CacheManager cacheManager = super.getObject();
Map<String, CacheConfiguration> cacheConfig = cacheManager.getConfiguration().getCacheConfigurations();
List<CacheConfiguration> cacheConfigurations = CachePropertiesUtil.getCacheConfigurations();
cacheConfigurations.stream().filter(cc -> cacheConfig.get(cc.getName()) == null).forEach(cc -> cacheManager.addCache(new Cache(cc)));
return cacheManager;
}
Aggregations