use of org.xwiki.cache.config.LRUCacheConfiguration in project xwiki-platform by xwiki.
the class ParseGroovyFromString method initCache.
private void initCache(int iClassCapacity, XWikiContext context) throws XWikiException {
try {
CacheConfiguration configuration = new LRUCacheConfiguration("xwiki.groovy.class", iClassCapacity);
this.classCache = this.cacheManager.createNewLocalCache(configuration);
} catch (CacheException e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to initilize caches", e);
}
}
use of org.xwiki.cache.config.LRUCacheConfiguration in project xwiki-platform by xwiki.
the class DefaultOfficeResourceViewer method initialize.
@Override
public void initialize() throws InitializationException {
try {
LRUCacheConfiguration attachmentConfig = new LRUCacheConfiguration(MODULE_NAME + ".attachment", 50);
this.attachmentCache = this.cacheManager.createNewCache(attachmentConfig);
// We have no idea when to invalidate the cache so lets at least put a time to live
LRUCacheConfiguration exteralConfig = new LRUCacheConfiguration(MODULE_NAME + ".external", 50, 3600);
this.externalCache = this.cacheManager.createNewCache(exteralConfig);
} catch (CacheException e) {
throw new InitializationException("Failed to create caches.", e);
}
}
use of org.xwiki.cache.config.LRUCacheConfiguration in project xwiki-platform by xwiki.
the class CacheMacro method getContentCache.
/**
* Get a cache matching the passed time to live and max entries.
* <p>
* Note that whenever a new cache is created it currently means a new thread is used too (since the JBoss cache used
* underneath uses a thread for evicting entries from the cache). We need to modify our xwiki-cache module to allow
* setting time to live on cache items, see https://jira.xwiki.org/browse/XWIKI-5907
* </p>
*
* @param lifespan the number of seconds to cache the content
* @param maxEntries the maximum number of entries in the cache (Least Recently Used entries are ejected)
* @return the matching cache (a new cache is created if no existing one is found)
* @throws MacroExecutionException in case we fail to create the new cache
*/
Cache<List<Block>> getContentCache(int lifespan, int maxEntries) throws MacroExecutionException {
CacheKey cacheKey = new CacheKey(lifespan, maxEntries);
Cache<List<Block>> contentCache = this.contentCacheMap.get(cacheKey);
if (contentCache == null) {
// Create Cache
LRUCacheConfiguration configuration = new LRUCacheConfiguration(String.format("cacheMacro.%s", cacheKey.toString()), maxEntries);
configuration.getLRUEvictionConfiguration().setLifespan(lifespan);
try {
contentCache = this.cacheManager.createNewLocalCache(configuration);
} catch (CacheException e) {
throw new MacroExecutionException("Failed to create content cache", e);
}
this.contentCacheMap.put(cacheKey, contentCache);
}
return contentCache;
}
Aggregations