Search in sources :

Example 16 with CacheConfiguration

use of org.xwiki.cache.config.CacheConfiguration 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 17 with CacheConfiguration

use of org.xwiki.cache.config.CacheConfiguration 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)

Example 18 with CacheConfiguration

use of org.xwiki.cache.config.CacheConfiguration in project xwiki-platform by xwiki.

the class DefaultRenderingCache method initialize.

@Override
public void initialize() throws InitializationException {
    if (this.configuration.isEnabled()) {
        CacheConfiguration cacheConfiguration = new CacheConfiguration();
        cacheConfiguration.setConfigurationId(NAME);
        LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
        lru.setMaxEntries(this.configuration.getSize());
        lru.setLifespan(this.configuration.getDuration());
        cacheConfiguration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
        try {
            this.cache.create(cacheConfiguration);
        } catch (CacheException e) {
            throw new InitializationException("Failed to initialize core rendering cache", e);
        }
    }
}
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 19 with CacheConfiguration

use of org.xwiki.cache.config.CacheConfiguration in project xwiki-platform by xwiki.

the class XWikiGroupServiceImpl method initCache.

@Override
public synchronized void initCache(int iCapacity, XWikiContext context) throws XWikiException {
    try {
        CacheConfiguration configuration = new CacheConfiguration();
        configuration.setConfigurationId("xwiki.groupservice.usergroups");
        LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
        lru.setMaxEntries(iCapacity);
        configuration.put(EntryEvictionConfiguration.CONFIGURATIONID, lru);
        this.memberGroupsCache = Utils.getComponent(CacheManager.class).createNewCache(configuration);
    } catch (CacheException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to initialize 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)

Aggregations

CacheConfiguration (org.xwiki.cache.config.CacheConfiguration)19 CacheException (org.xwiki.cache.CacheException)14 LRUEvictionConfiguration (org.xwiki.cache.eviction.LRUEvictionConfiguration)9 InitializationException (org.xwiki.component.phase.InitializationException)7 XWikiException (com.xpn.xwiki.XWikiException)6 CacheFactory (org.xwiki.cache.CacheFactory)5 CacheManager (org.xwiki.cache.CacheManager)3 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)3 Before (org.junit.Before)2 Cache (org.xwiki.cache.Cache)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 Expectations (org.jmock.Expectations)1 LRUCacheConfiguration (org.xwiki.cache.config.LRUCacheConfiguration)1 DefaultParameterizedType (org.xwiki.component.util.DefaultParameterizedType)1 IconSet (org.xwiki.icon.IconSet)1 NamedColorThemeReference (org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference)1 LESSSkinFileResourceReference (org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference)1 FSSkinReference (org.xwiki.lesscss.internal.skin.FSSkinReference)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1