use of org.xwiki.cache.CacheException in project xwiki-platform by xwiki.
the class CacheImageStorage method initialize.
@Override
public void initialize() throws InitializationException {
CacheConfiguration configuration = new CacheConfiguration();
configuration.setConfigurationId("xwiki.plugin.formula");
try {
this.cache = this.cacheManager.createNewCache(configuration);
} catch (CacheException e) {
throw new InitializationException("Failed to create cache", e);
}
}
use of org.xwiki.cache.CacheException in project xwiki-platform by xwiki.
the class DefaultIconSetCache method initialize.
@Override
public void initialize() throws InitializationException {
try {
CacheConfiguration configuration = new CacheConfiguration(ICON_SET_CACHE_ID);
CacheFactory cacheFactory = cacheManager.getCacheFactory();
this.cache = cacheFactory.newCache(configuration);
} catch (ComponentLookupException | CacheException e) {
throw new InitializationException("Failed to initialize the IconSet Cache.", e);
}
}
use of org.xwiki.cache.CacheException in project xwiki-platform by xwiki.
the class RepositoryManager method initialize.
@Override
public void initialize() throws InitializationException {
// Init cache
CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setConfigurationId("repository.extensionid.documentreference");
LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
lru.setMaxEntries(10000);
cacheConfiguration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
try {
this.documentReferenceCache = this.cacheManager.createNewCache(cacheConfiguration);
} catch (CacheException e) {
throw new InitializationException("Failed to initialize cache", e);
}
// Listen to modifications
this.observation.addListener(listener);
}
use of org.xwiki.cache.CacheException in project xwiki-platform by xwiki.
the class DefaultIconSetCacheTest method initializeWhenError.
@Test
public void initializeWhenError() throws Exception {
DefaultIconSetCache cache = mocker.getComponentUnderTest();
CacheFactory cacheFactory = mock(CacheFactory.class);
when(cacheManager.getCacheFactory()).thenReturn(cacheFactory);
Exception exception = new CacheException("ERROR");
when(cacheFactory.newCache(any(CacheConfiguration.class))).thenThrow(exception);
Exception exceptionCaught = null;
try {
cache.initialize();
} catch (InitializationException e) {
exceptionCaught = e;
}
assertNotNull(exceptionCaught);
assertEquals("Failed to initialize the IconSet Cache.", exceptionCaught.getMessage());
assertEquals(exception, exceptionCaught.getCause());
}
use of org.xwiki.cache.CacheException in project xwiki-platform by xwiki.
the class ImagePlugin method initCache.
/**
* Tries to initializes the image cache. If the initialization fails the image cache remains {@code null}.
*
* @param context the XWiki context
*/
private void initCache(XWikiContext context) {
if (this.imageCache == null) {
CacheConfiguration configuration = new CacheConfiguration();
configuration.setConfigurationId("xwiki.plugin.image");
// Set cache constraints.
LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
configuration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
String capacityParam = context.getWiki().Param("xwiki.plugin.image.cache.capacity");
if (!StringUtils.isBlank(capacityParam) && StringUtils.isNumeric(capacityParam.trim())) {
try {
this.capacity = Integer.parseInt(capacityParam.trim());
} catch (NumberFormatException e) {
LOG.warn(String.format("Failed to parse xwiki.plugin.image.cache.capacity configuration parameter. " + "Using %s as the cache capacity.", this.capacity), e);
}
}
lru.setMaxEntries(this.capacity);
try {
this.imageCache = Utils.getComponent(CacheManager.class).createNewLocalCache(configuration);
} catch (CacheException e) {
LOG.error("Error initializing the image cache.", e);
}
}
}
Aggregations