Search in sources :

Example 1 with LRUEvictionConfiguration

use of org.xwiki.cache.eviction.LRUEvictionConfiguration in project xwiki-platform by xwiki.

the class XWikiCacheServiceStub method newCache.

@Override
public XWikiCache newCache(String cacheName, int capacity) throws XWikiException {
    CacheConfiguration configuration = new CacheConfiguration();
    configuration.setConfigurationId(cacheName);
    LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
    lru.setMaxEntries(capacity);
    configuration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
    try {
        return new XWikiCacheStub(this.cacheFactory.newCache(configuration));
    } catch (CacheException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to create new 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)

Example 2 with LRUEvictionConfiguration

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

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

use of org.xwiki.cache.eviction.LRUEvictionConfiguration in project xwiki-platform by xwiki.

the class XWikiCacheServiceStub method newLocalCache.

@Override
public XWikiCache newLocalCache(int capacity) throws XWikiException {
    CacheConfiguration configuration = new CacheConfiguration();
    LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
    lru.setMaxEntries(capacity);
    configuration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
    try {
        return new XWikiCacheStub(this.localCacheFactory.newCache(configuration));
    } catch (CacheException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to create new 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)

Example 5 with LRUEvictionConfiguration

use of org.xwiki.cache.eviction.LRUEvictionConfiguration in project xwiki-platform by xwiki.

the class DefaultDocumentCacheTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    this.cache = (DefaultDocumentCache<String>) getComponentManager().getInstance(DocumentCache.class);
    CacheConfiguration cacheConfiguration = new CacheConfiguration();
    cacheConfiguration.setConfigurationId("documentcachetest");
    LRUEvictionConfiguration lru = new LRUEvictionConfiguration();
    cacheConfiguration.put(LRUEvictionConfiguration.CONFIGURATIONID, lru);
    this.cache.create(cacheConfiguration);
    this.document = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
    this.document.setOriginalDocument(this.document.clone());
    this.mockXWiki = getMockery().mock(XWiki.class);
    getContext().setWiki(this.mockXWiki);
    getMockery().checking(new Expectations() {

        {
            allowing(mockXWiki).getDocument(document.getDocumentReference(), getContext());
            will(returnValue(document));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) LRUEvictionConfiguration(org.xwiki.cache.eviction.LRUEvictionConfiguration) XWiki(com.xpn.xwiki.XWiki) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference)

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