use of net.sf.ehcache.config.CacheConfiguration in project cloudbreak by hortonworks.
the class CloudResourceVmTypeCache method cacheConfiguration.
@Override
public CacheConfiguration cacheConfiguration() {
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName("cloudResourceVmTypeCache");
cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration.setMaxEntriesLocalHeap(MAX_ENTRIES);
return cacheConfiguration;
}
use of net.sf.ehcache.config.CacheConfiguration in project cloudbreak by hortonworks.
the class TokenCache method cacheConfiguration.
@Override
public CacheConfiguration cacheConfiguration() {
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setName("tokenCache");
cacheConfiguration.setMemoryStoreEvictionPolicy("LRU");
cacheConfiguration.setMaxEntriesLocalHeap(MAX_ENTRIES);
cacheConfiguration.setTimeToLiveSeconds(TTL_IN_SECONDS);
return cacheConfiguration;
}
use of net.sf.ehcache.config.CacheConfiguration in project coastal-hazards by USGS-CIDA.
the class CacheResource method clearCache.
boolean clearCache() {
boolean cleared = false;
try {
CacheConfiguration ehConfig = new CacheConfiguration().name(cacheName).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU).persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP)).maxBytesLocalDisk(10, MemoryUnit.MEGABYTES).maxBytesLocalHeap(1, MemoryUnit.MEGABYTES).clearOnFlush(true);
Configuration managerConfig = new Configuration().diskStore(new DiskStoreConfiguration().path(cacheLocation)).dynamicConfig(false).cache(ehConfig);
CacheManager cacheManager = CacheManager.create(managerConfig);
Ehcache ehcache = cacheManager.getEhcache(cacheName);
if (ehcache != null) {
ehcache.flush();
ehcache.removeAll();
cleared = true;
} else {
cleared = false;
}
} catch (Exception e) {
log.debug("Unable to clear cache", e);
cleared = false;
}
return cleared;
}
use of net.sf.ehcache.config.CacheConfiguration in project coastal-hazards by USGS-CIDA.
the class CacheResourceTest method testClearCache.
/**
* Test of clearCache method, of class CacheResource.
*/
@Test
public void testClearCache() {
CacheConfiguration ehConfig = new CacheConfiguration().name(CACHE_NAME).memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LRU).persistence(new PersistenceConfiguration().strategy(PersistenceConfiguration.Strategy.LOCALTEMPSWAP)).timeToLiveSeconds(1000).timeToIdleSeconds(1000).clearOnFlush(true);
Configuration managerConfig = new Configuration().diskStore(new DiskStoreConfiguration().path(CACHE_LOCATION)).maxBytesLocalHeap(1, MemoryUnit.MEGABYTES).maxBytesLocalDisk(100, MemoryUnit.MEGABYTES).dynamicConfig(false).cache(ehConfig);
CacheManager cacheManager = CacheManager.create(managerConfig);
Ehcache ehcache = cacheManager.getEhcache(CACHE_NAME);
for (int i = 0; i < 100; i++) {
Element e = new Element(i, "value" + i);
ehcache.put(e);
}
assertThat(ehcache.getSize(), is(equalTo(100)));
CacheResource instance = new CacheResource();
boolean cleared = instance.clearCache();
assertThat(cleared, is(equalTo(true)));
assertThat(ehcache.getSize(), is(equalTo(0)));
}
use of net.sf.ehcache.config.CacheConfiguration in project gravitee-gateway by gravitee-io.
the class SubscriptionsCacheConfiguration method cache.
@Bean
public Cache cache() {
CacheManager cacheManager = cacheManager();
Cache apiKeyCache = cacheManager.getCache(CACHE_NAME);
if (apiKeyCache == null) {
LOGGER.warn("EHCache cache for " + CACHE_NAME + " not found. Fallback to default EHCache configuration");
CacheConfiguration cacheConfiguration = new CacheConfiguration(CACHE_NAME, 1000);
cacheManager.addCache(new Cache(cacheConfiguration));
}
return cacheManager.getCache(CACHE_NAME);
}
Aggregations