Search in sources :

Example 11 with CacheException

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

Example 12 with CacheException

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);
    }
}
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 13 with CacheException

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

Example 14 with CacheException

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

Example 15 with CacheException

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);
        }
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) LRUEvictionConfiguration(org.xwiki.cache.eviction.LRUEvictionConfiguration) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration)

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