Search in sources :

Example 6 with LRUEvictionConfiguration

use of org.xwiki.cache.eviction.LRUEvictionConfiguration 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 7 with LRUEvictionConfiguration

use of org.xwiki.cache.eviction.LRUEvictionConfiguration 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 8 with LRUEvictionConfiguration

use of org.xwiki.cache.eviction.LRUEvictionConfiguration 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 9 with LRUEvictionConfiguration

use of org.xwiki.cache.eviction.LRUEvictionConfiguration 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)9 LRUEvictionConfiguration (org.xwiki.cache.eviction.LRUEvictionConfiguration)9 CacheException (org.xwiki.cache.CacheException)7 XWikiException (com.xpn.xwiki.XWikiException)4 InitializationException (org.xwiki.component.phase.InitializationException)3 XWiki (com.xpn.xwiki.XWiki)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 Expectations (org.jmock.Expectations)1 CacheManager (org.xwiki.cache.CacheManager)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 ConflictingInsertionException (org.xwiki.security.authorization.cache.ConflictingInsertionException)1 ParentEntryEvictedException (org.xwiki.security.authorization.cache.ParentEntryEvictedException)1