Search in sources :

Example 6 with CacheConfiguration

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

the class FeedPlugin method initCache.

public void initCache(int iCapacity, XWikiContext context) throws XWikiException {
    try {
        CacheConfiguration configuration = new CacheConfiguration();
        configuration.setConfigurationId("xwiki.plugin.feedcache");
        LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
        lru.setMaxEntries(iCapacity);
        lru.setMaxIdle(this.refreshPeriod);
        configuration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
        CacheManager cacheManager = Utils.getComponent(CacheManager.class);
        this.feedCache = cacheManager.createNewLocalCache(configuration);
    } catch (CacheException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to create cache");
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) LRUEvictionConfiguration(org.xwiki.cache.eviction.LRUEvictionConfiguration) CacheManager(org.xwiki.cache.CacheManager) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) XWikiException(com.xpn.xwiki.XWikiException)

Example 7 with CacheConfiguration

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

the class DocumentTranslationBundleFactory method initialize.

@Override
public void initialize() throws InitializationException {
    // Cache
    CacheConfiguration cacheConfiguration = new CacheConfiguration("localization.bundle.document");
    try {
        this.onDemandBundleCache = this.cacheManager.createNewCache(cacheConfiguration);
    } catch (CacheException e) {
        this.logger.error("Failed to create cache [{}]", cacheConfiguration.getConfigurationId(), e);
    }
    // Load existing translations from main wiki, wait for WikiReaderEvent for other wikis
    loadTranslations(this.wikiManager.getMainWikiId());
    // Listeners
    this.observation.addListener(this.listener);
    this.observation.addListener(this.wikilistener);
}
Also used : CacheException(org.xwiki.cache.CacheException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration)

Example 8 with CacheConfiguration

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

the class DefaultSecurityCache method newCache.

/**
 * @return a new configured security cache
 * @throws InitializationException if a CacheException arise during creation
 */
private Cache<SecurityCacheEntry> newCache() throws InitializationException {
    CacheConfiguration cacheConfig = new CacheConfiguration();
    cacheConfig.setConfigurationId("platform.security.authorization.cache");
    LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
    lru.setMaxEntries(DEFAULT_CAPACITY);
    cacheConfig.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
    try {
        return cacheManager.createNewCache(cacheConfig);
    } catch (Exception e) {
        throw new InitializationException(String.format("Unable to create the security cache with a capacity of [%d] entries", lru.getMaxEntries()), e);
    }
}
Also used : LRUEvictionConfiguration(org.xwiki.cache.eviction.LRUEvictionConfiguration) InitializationException(org.xwiki.component.phase.InitializationException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) InitializationException(org.xwiki.component.phase.InitializationException) ParentEntryEvictedException(org.xwiki.security.authorization.cache.ParentEntryEvictedException) ConflictingInsertionException(org.xwiki.security.authorization.cache.ConflictingInsertionException)

Example 9 with CacheConfiguration

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

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

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