Search in sources :

Example 6 with CacheException

use of org.xwiki.cache.CacheException in project xwiki-platform by xwiki.

the class DefaultColorThemeCache method initialize.

@Override
public void initialize() throws InitializationException {
    try {
        // Create the cache
        CacheConfiguration configuration = new CacheConfiguration(LESS_COLOR_THEMES_CACHE_ID);
        CacheFactory cacheFactory = cacheManager.getCacheFactory();
        super.cache = cacheFactory.newCache(configuration);
        // The Color Theme only depends on colors which do not depend on the XWikiContext. So we don't handle the
        // XWikiContext in this cache.
        super.isContextHandled = false;
    } catch (ComponentLookupException | CacheException e) {
        throw new InitializationException(String.format("Failed to initialize LESS color themes cache [%s].", LESS_COLOR_THEMES_CACHE_ID), e);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) CacheFactory(org.xwiki.cache.CacheFactory) InitializationException(org.xwiki.component.phase.InitializationException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration)

Example 7 with CacheException

use of org.xwiki.cache.CacheException in project xwiki-platform by xwiki.

the class DefaultLESSResourcesCache method initialize.

@Override
public void initialize() throws InitializationException {
    try {
        CacheConfiguration configuration = new CacheConfiguration(LESS_FILES_CACHE_ID);
        CacheFactory cacheFactory = cacheManager.getCacheFactory();
        this.cache = cacheFactory.newCache(configuration);
    } catch (ComponentLookupException | CacheException e) {
        throw new InitializationException(String.format("Failed to initialize LESS skin files cache [%s].", LESS_FILES_CACHE_ID), e);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) CacheFactory(org.xwiki.cache.CacheFactory) InitializationException(org.xwiki.component.phase.InitializationException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration)

Example 8 with CacheException

use of org.xwiki.cache.CacheException in project xwiki-platform by xwiki.

the class XWikiCacheServiceStub method newCache.

@Override
public XWikiCache newCache(String cacheName) throws XWikiException {
    CacheConfiguration configuration = new CacheConfiguration();
    configuration.setConfigurationId(cacheName);
    try {
        return new XWikiCacheStub(this.cacheFactory.newCache(configuration));
    } catch (CacheException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to create new cache", e);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) XWikiException(com.xpn.xwiki.XWikiException)

Example 9 with CacheException

use of org.xwiki.cache.CacheException in project xwiki-platform by xwiki.

the class XWikiCacheServiceStub method newLocalCache.

@Override
public XWikiCache newLocalCache(int capacity) throws XWikiException {
    CacheConfiguration configuration = new CacheConfiguration();
    LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
    lru.setMaxEntries(capacity);
    configuration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
    try {
        return new XWikiCacheStub(this.localCacheFactory.newCache(configuration));
    } catch (CacheException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to create new cache", e);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) LRUEvictionConfiguration(org.xwiki.cache.eviction.LRUEvictionConfiguration) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) XWikiException(com.xpn.xwiki.XWikiException)

Example 10 with CacheException

use of org.xwiki.cache.CacheException 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)17 CacheConfiguration (org.xwiki.cache.config.CacheConfiguration)15 InitializationException (org.xwiki.component.phase.InitializationException)8 LRUEvictionConfiguration (org.xwiki.cache.eviction.LRUEvictionConfiguration)7 XWikiException (com.xpn.xwiki.XWikiException)6 CacheFactory (org.xwiki.cache.CacheFactory)4 LRUCacheConfiguration (org.xwiki.cache.config.LRUCacheConfiguration)3 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)3 List (java.util.List)1 Test (org.junit.Test)1 CacheManager (org.xwiki.cache.CacheManager)1 MacroExecutionException (org.xwiki.rendering.macro.MacroExecutionException)1