Search in sources :

Example 16 with CacheConfiguration

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;
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 17 with 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;
}
Also used : CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 18 with 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;
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) CacheManager(net.sf.ehcache.CacheManager) Ehcache(net.sf.ehcache.Ehcache) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration)

Example 19 with CacheConfiguration

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)));
}
Also used : PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) PersistenceConfiguration(net.sf.ehcache.config.PersistenceConfiguration) Element(net.sf.ehcache.Element) CacheManager(net.sf.ehcache.CacheManager) Ehcache(net.sf.ehcache.Ehcache) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Test(org.junit.Test)

Example 20 with CacheConfiguration

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);
}
Also used : CacheManager(net.sf.ehcache.CacheManager) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache) Bean(org.springframework.context.annotation.Bean)

Aggregations

CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)71 Cache (net.sf.ehcache.Cache)26 CacheManager (net.sf.ehcache.CacheManager)16 Ehcache (net.sf.ehcache.Ehcache)14 Configuration (net.sf.ehcache.config.Configuration)14 Element (net.sf.ehcache.Element)9 PersistenceConfiguration (net.sf.ehcache.config.PersistenceConfiguration)8 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)6 Test (org.junit.Test)6 Resource (org.springframework.core.io.Resource)6 IOException (java.io.IOException)5 Bean (org.springframework.context.annotation.Bean)5 CachedResource (org.apereo.portal.utils.cache.resource.CachedResource)4 CachingResourceLoaderImpl (org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl)4 LoadedResource (org.apereo.portal.utils.cache.resource.LoadedResource)4 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 FileReader (java.io.FileReader)3 URL (java.net.URL)3 SelfPopulatingCache (net.sf.ehcache.constructs.blocking.SelfPopulatingCache)3