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