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;
}
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);
}
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);
}
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;
}
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;
}
Aggregations