Search in sources :

Example 11 with Ehcache

use of net.sf.ehcache.Ehcache in project killbill by killbill.

the class EhCacheCacheManagerProvider method get.

@Override
public CacheManager get() {
    final CacheManager cacheManager;
    try {
        final InputStream inputStream = UriAccessor.accessUri(cacheConfig.getCacheConfigLocation());
        cacheManager = CacheManager.create(inputStream);
    } catch (final IOException e) {
        throw new RuntimeException(e);
    } catch (final URISyntaxException e) {
        throw new RuntimeException(e);
    }
    for (final BaseCacheLoader cacheLoader : cacheLoaders) {
        cacheLoader.init();
        final Ehcache cache = cacheManager.getEhcache(cacheLoader.getCacheType().getCacheName());
        if (cache == null) {
            logger.warn("Cache for cacheName='{}' not configured - check your ehcache.xml", cacheLoader.getCacheType().getCacheName());
            continue;
        }
        // Make sure we start from a clean state - this is mainly useful for tests
        for (final CacheLoader existingCacheLoader : cache.getRegisteredCacheLoaders()) {
            cache.unregisterCacheLoader(existingCacheLoader);
        }
        cache.registerCacheLoader(cacheLoader);
        // Instrument the cache
        final Ehcache decoratedCache = InstrumentedEhcache.instrument(metricRegistry, cache);
        try {
            cacheManager.replaceCacheWithDecoratedCache(cache, decoratedCache);
        } catch (final CacheException e) {
            logger.warn("Unable to instrument cache {}: {}", cache.getName(), e.getMessage());
        }
    }
    return cacheManager;
}
Also used : CacheException(net.sf.ehcache.CacheException) InputStream(java.io.InputStream) CacheManager(net.sf.ehcache.CacheManager) InstrumentedEhcache(com.codahale.metrics.ehcache.InstrumentedEhcache) Ehcache(net.sf.ehcache.Ehcache) CacheLoader(net.sf.ehcache.loader.CacheLoader) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException)

Example 12 with Ehcache

use of net.sf.ehcache.Ehcache in project spring-security by spring-projects.

the class BasicLookupStrategyTests method getCache.

private Ehcache getCache() {
    Ehcache cache = cacheManager.getCache("basiclookuptestcache");
    cache.removeAll();
    return cache;
}
Also used : Ehcache(net.sf.ehcache.Ehcache)

Example 13 with Ehcache

use of net.sf.ehcache.Ehcache in project spring-security by spring-projects.

the class EhCacheBasedTicketCacheTests method testStartupDetectsMissingCache.

@Test
public void testStartupDetectsMissingCache() throws Exception {
    EhCacheBasedTicketCache cache = new EhCacheBasedTicketCache();
    try {
        cache.afterPropertiesSet();
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
    }
    Ehcache myCache = cacheManager.getCache("castickets");
    cache.setCache(myCache);
    assertThat(cache.getCache()).isEqualTo(myCache);
}
Also used : EhCacheBasedTicketCache(org.springframework.security.cas.authentication.EhCacheBasedTicketCache) Ehcache(net.sf.ehcache.Ehcache) Test(org.junit.Test)

Example 14 with Ehcache

use of net.sf.ehcache.Ehcache in project spring-security by spring-projects.

the class EhCacheBasedUserCacheTests method getCache.

private Ehcache getCache() {
    Ehcache cache = cacheManager.getCache("ehcacheusercachetests");
    cache.removeAll();
    return cache;
}
Also used : Ehcache(net.sf.ehcache.Ehcache)

Example 15 with Ehcache

use of net.sf.ehcache.Ehcache in project OpenClinica by OpenClinica.

the class EhCacheWrapper method get.

public V get(final K key) {
    String db_type = CoreResources.getField("dbType");
    if (db_type.equalsIgnoreCase("postgres")) {
        Element element = null;
        Ehcache ehCache = getCache();
        if (ehCache != null) {
            element = getCache().get(key);
            logMe("element  null" + element);
        }
        if (element != null) {
            logMe("element not null" + element);
            return (V) element.getObjectValue();
        }
    }
    return null;
}
Also used : Element(net.sf.ehcache.Element) Ehcache(net.sf.ehcache.Ehcache)

Aggregations

Ehcache (net.sf.ehcache.Ehcache)39 Test (org.junit.Test)14 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)9 Element (net.sf.ehcache.Element)8 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)7 CacheException (net.sf.ehcache.CacheException)5 CacheManager (net.sf.ehcache.CacheManager)5 CachedResource (org.apereo.portal.utils.cache.resource.CachedResource)5 CachingResourceLoaderImpl (org.apereo.portal.utils.cache.resource.CachingResourceLoaderImpl)5 LoadedResource (org.apereo.portal.utils.cache.resource.LoadedResource)5 FileSystemResource (org.springframework.core.io.FileSystemResource)5 Resource (org.springframework.core.io.Resource)5 CacheKey (org.apereo.portal.utils.cache.CacheKey)4 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 Test (org.testng.annotations.Test)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 FileReader (java.io.FileReader)3 InputStream (java.io.InputStream)3