Search in sources :

Example 1 with LRUCacheConfiguration

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);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) LRUCacheConfiguration(org.xwiki.cache.config.LRUCacheConfiguration) XWikiException(com.xpn.xwiki.XWikiException) LRUCacheConfiguration(org.xwiki.cache.config.LRUCacheConfiguration)

Example 2 with LRUCacheConfiguration

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);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) InitializationException(org.xwiki.component.phase.InitializationException) LRUCacheConfiguration(org.xwiki.cache.config.LRUCacheConfiguration)

Example 3 with LRUCacheConfiguration

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;
}
Also used : CacheException(org.xwiki.cache.CacheException) MacroExecutionException(org.xwiki.rendering.macro.MacroExecutionException) List(java.util.List) LRUCacheConfiguration(org.xwiki.cache.config.LRUCacheConfiguration)

Aggregations

CacheException (org.xwiki.cache.CacheException)3 LRUCacheConfiguration (org.xwiki.cache.config.LRUCacheConfiguration)3 XWikiException (com.xpn.xwiki.XWikiException)1 List (java.util.List)1 CacheConfiguration (org.xwiki.cache.config.CacheConfiguration)1 InitializationException (org.xwiki.component.phase.InitializationException)1 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)1