Search in sources :

Example 46 with Ehcache

use of net.sf.ehcache.Ehcache in project uPortal by Jasig.

the class TagTrackingCacheEventListener method purgeCacheEntries.

/**
 * Remove all cache entries with keys that have the specified tag
 */
@Override
public int purgeCacheEntries(CacheEntryTag tag) {
    final String tagType = tag.getTagType();
    final Set<Ehcache> caches = taggedCaches.getIfPresent(tagType);
    // Tag exists in cache(s)
    if (caches == null || caches.isEmpty()) {
        return 0;
    }
    int purgeCount = 0;
    // Iterate over each cache to remove the tagged entries
    for (final Ehcache cache : caches) {
        final String cacheName = cache.getName();
        // See if there are any tagged cache keys for the cache
        final LoadingCache<CacheEntryTag, Set<Object>> cacheKeys = taggedCacheKeys.getIfPresent(cacheName);
        if (cacheKeys != null) {
            // Remove all cache keys from the cache
            final Set<Object> taggedKeys = cacheKeys.asMap().remove(tag);
            if (taggedKeys != null) {
                final int keyCount = taggedKeys.size();
                purgeCount += keyCount;
                logger.debug("Removing {} keys from {} for tag {}", keyCount, cacheName, tag);
                cache.removeAll(taggedKeys);
            }
        }
    }
    return purgeCount;
}
Also used : Set(java.util.Set) Ehcache(net.sf.ehcache.Ehcache)

Example 47 with Ehcache

use of net.sf.ehcache.Ehcache in project cxf by apache.

the class EHCacheXKMSClientCache method createCache.

private void createCache(String configFile, Bus cxfBus) {
    if (cxfBus == null) {
        cxfBus = BusFactory.getThreadDefaultBus(true);
    }
    URL configFileURL = null;
    try {
        configFileURL = ClassLoaderUtils.getResource(configFile, EHCacheXKMSClientCache.class);
    } catch (Exception ex) {
    // ignore
    }
    if (configFileURL == null) {
        cacheManager = EHCacheUtil.createCacheManager();
    } else {
        Configuration conf = ConfigurationFactory.parseConfiguration(configFileURL);
        if (cxfBus != null) {
            conf.setName(cxfBus.getId());
            DiskStoreConfiguration dsc = conf.getDiskStoreConfiguration();
            if (dsc != null && "java.io.tmpdir".equals(dsc.getOriginalPath())) {
                String path = conf.getDiskStoreConfiguration().getPath() + File.separator + cxfBus.getId();
                conf.getDiskStoreConfiguration().setPath(path);
            }
        }
        cacheManager = EHCacheUtil.createCacheManager(conf);
    }
    CacheConfiguration cc = EHCacheUtil.getCacheConfiguration(CACHE_KEY, cacheManager);
    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
Also used : DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) Ehcache(net.sf.ehcache.Ehcache) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) URL(java.net.URL) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 48 with Ehcache

use of net.sf.ehcache.Ehcache in project cxf by apache.

the class EHCacheTokenReplayCache method createCache.

private void createCache(String configFile, Bus bus) {
    if (bus == null) {
        bus = BusFactory.getThreadDefaultBus(true);
    }
    URL configFileURL = null;
    try {
        configFileURL = ResourceUtils.getClasspathResourceURL(configFile, EHCacheTokenReplayCache.class, bus);
    } catch (Exception ex) {
    // ignore
    }
    if (configFileURL == null) {
        cacheManager = EHCacheUtil.createCacheManager();
    } else {
        Configuration conf = ConfigurationFactory.parseConfiguration(configFileURL);
        if (bus != null) {
            conf.setName(bus.getId());
            DiskStoreConfiguration dsc = conf.getDiskStoreConfiguration();
            if (dsc != null && "java.io.tmpdir".equals(dsc.getOriginalPath())) {
                String path = conf.getDiskStoreConfiguration().getPath() + File.separator + bus.getId();
                conf.getDiskStoreConfiguration().setPath(path);
            }
        }
        cacheManager = EHCacheUtil.createCacheManager(conf);
    }
    CacheConfiguration cc = EHCacheUtil.getCacheConfiguration(CACHE_KEY, cacheManager);
    Ehcache newCache = new Cache(cc);
    cache = cacheManager.addCacheIfAbsent(newCache);
}
Also used : DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Configuration(net.sf.ehcache.config.Configuration) Ehcache(net.sf.ehcache.Ehcache) DiskStoreConfiguration(net.sf.ehcache.config.DiskStoreConfiguration) URL(java.net.URL) IOException(java.io.IOException) CacheConfiguration(net.sf.ehcache.config.CacheConfiguration) Cache(net.sf.ehcache.Cache)

Example 49 with Ehcache

use of net.sf.ehcache.Ehcache in project vertigo by KleeGroup.

the class EhCachePlugin method getEHCache.

private Ehcache getEHCache(final String context) {
    final Ehcache ehCache = manager.getCache(context);
    Assertion.checkNotNull(ehCache, "Cache {0} are not yet registered. Add it into a file ehcache.xml and put it into the WEB-INF directory of your webapp.", context);
    return ehCache;
}
Also used : Ehcache(net.sf.ehcache.Ehcache)

Example 50 with Ehcache

use of net.sf.ehcache.Ehcache in project onebusaway-application-modules by camsys.

the class EhCacheFactoryBean method afterPropertiesSet.

public void afterPropertiesSet() throws CacheException, IOException {
    // If no CacheManager given, fetch the default.
    if (this.cacheManager == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Using default EHCache CacheManager for cache region '" + this.cacheName + "'");
        }
        this.cacheManager = CacheManager.getInstance();
    }
    // If no cache name given, use bean name as cache name.
    if (this.cacheName == null) {
        this.cacheName = this.beanName;
    }
    // Fetch cache region: If none with the given name exists,
    // create one on the fly.
    Ehcache rawCache = null;
    if (this.cacheManager.cacheExists(this.cacheName)) {
        if (logger.isDebugEnabled()) {
            logger.debug("Using existing EHCache cache region '" + this.cacheName + "'");
        }
        rawCache = this.cacheManager.getEhcache(this.cacheName);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating new EHCache cache region '" + this.cacheName + "'");
        }
        rawCache = createCache();
        this.cacheManager.addCache(rawCache);
    }
    // Decorate cache if necessary.
    Ehcache decoratedCache = decorateCache(rawCache);
    if (decoratedCache != rawCache) {
        this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);
    }
    this.cache = decoratedCache;
}
Also used : Ehcache(net.sf.ehcache.Ehcache)

Aggregations

Ehcache (net.sf.ehcache.Ehcache)51 Test (org.junit.Test)15 CacheConfiguration (net.sf.ehcache.config.CacheConfiguration)14 Element (net.sf.ehcache.Element)11 ResourcesElementsProvider (org.jasig.resourceserver.utils.aggr.ResourcesElementsProvider)9 Cache (net.sf.ehcache.Cache)7 CacheManager (net.sf.ehcache.CacheManager)7 CacheException (net.sf.ehcache.CacheException)6 Configuration (net.sf.ehcache.config.Configuration)5 DiskStoreConfiguration (net.sf.ehcache.config.DiskStoreConfiguration)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 CacheKey (org.apereo.portal.utils.cache.CacheKey)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 Resource (org.springframework.core.io.Resource)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 FileReader (java.io.FileReader)3 IOException (java.io.IOException)3