use of net.sf.ehcache.config.CacheConfiguration in project openmrs-core by openmrs.
the class CachePropertiesUtil method addCacheConfigsFormResourceToList.
private static void addCacheConfigsFormResourceToList(Resource resource, List<CacheConfiguration> openmrsCacheConfigurationList) {
Properties cacheProperties = getPropertiesFromResource(resource);
getAllCacheNames(cacheProperties.keySet()).forEach(cacheName -> {
OpenmrsCacheConfiguration openmrsCacheConfiguration = new OpenmrsCacheConfiguration();
openmrsCacheConfiguration.addProperty("name", cacheName);
cacheProperties.keySet().stream().filter(key -> key.toString().startsWith(cacheName)).forEach(key -> {
String s = key.toString();
openmrsCacheConfiguration.addProperty(s.replace(cacheName + ".", ""), cacheProperties.getProperty(key.toString()));
});
openmrsCacheConfigurationList.add(createCacheConfiguration(openmrsCacheConfiguration));
});
}
use of net.sf.ehcache.config.CacheConfiguration 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;
}
use of net.sf.ehcache.config.CacheConfiguration in project ff4j by ff4j.
the class FeatureStoreTerracottaTestIT method initStore.
/**
* {@inheritDoc}
*/
@Override
protected FeatureStore initStore() {
// Configuration to wirk with Terracotta
Configuration managerConfiguration = new Configuration();
managerConfiguration.name("config").terracotta(new TerracottaClientConfiguration().url(TERRACOTTA_URL)).defaultCache(new CacheConfiguration().maxBytesLocalHeap(128, MemoryUnit.MEGABYTES).terracotta(new TerracottaConfiguration())).cache(new CacheConfiguration().name(FF4jEhCacheWrapper.CACHENAME_FEATURES).maxBytesLocalHeap(128, MemoryUnit.MEGABYTES).terracotta(new TerracottaConfiguration()));
FeatureStoreEhCache ehcacheStore = new FeatureStoreEhCache(managerConfiguration);
ehcacheStore.importFeaturesFromXmlFile("ff4j.xml");
return ehcacheStore;
}
use of net.sf.ehcache.config.CacheConfiguration in project mica2 by obiba.
the class DatasetCacheResolver method resolveCaches.
@Override
public synchronized Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> cacheOperationInvocationContext) {
Collection<Cache> res = Lists.newArrayList();
Optional<Object> dataset = Arrays.stream(cacheOperationInvocationContext.getArgs()).filter(o -> o instanceof Dataset).findFirst();
if (dataset.isPresent()) {
String cacheName = "dataset-" + ((Dataset) dataset.get()).getId();
Cache datasetCache = springCacheManager.getCache(cacheName);
if (datasetCache == null) {
CacheConfiguration conf = cacheManager.getEhcache("dataset-variables").getCacheConfiguration().clone();
conf.setName(cacheName);
cacheManager.addCache(new net.sf.ehcache.Cache(conf));
net.sf.ehcache.Cache cache = cacheManager.getCache(cacheName);
cacheManager.replaceCacheWithDecoratedCache(cache, InstrumentedEhcache.instrument(metricRegistry, cache));
datasetCache = new EhCacheCache(cacheManager.getEhcache(cacheName));
}
res.add(datasetCache);
}
return res;
}
use of net.sf.ehcache.config.CacheConfiguration in project dble by actiontech.
the class EnchachePooFactory method createCachePool.
@Override
public CachePool createCachePool(String poolName, int cacheSize, int expiredSeconds) {
CacheManager cacheManager = CacheManager.create();
Cache enCache = cacheManager.getCache(poolName);
if (enCache == null) {
CacheConfiguration cacheConf = cacheManager.getConfiguration().getDefaultCacheConfiguration().clone();
cacheConf.setName(poolName);
if (cacheConf.getMaxEntriesLocalHeap() != 0) {
cacheConf.setMaxEntriesLocalHeap(cacheSize);
} else {
cacheConf.setMaxBytesLocalHeap(String.valueOf(cacheSize));
}
cacheConf.setTimeToIdleSeconds(expiredSeconds);
Cache cache = new Cache(cacheConf);
cacheManager.addCache(cache);
return new EnchachePool(poolName, cache, cacheSize);
} else {
return new EnchachePool(poolName, enCache, cacheSize);
}
}
Aggregations