Search in sources :

Example 1 with CacheConfiguration

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

the class ParseGroovyFromString method initCache.

private void initCache(int iClassCapacity, XWikiContext context) throws XWikiException {
    try {
        CacheConfiguration configuration = new LRUCacheConfiguration("xwiki.groovy.class", iClassCapacity);
        this.classCache = this.cacheManager.createNewLocalCache(configuration);
    } catch (CacheException e) {
        throw new XWikiException(XWikiException.MODULE_XWIKI_CACHE, XWikiException.ERROR_CACHE_INITIALIZING, "Failed to initilize caches", e);
    }
}
Also used : CacheException(org.xwiki.cache.CacheException) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) LRUCacheConfiguration(org.xwiki.cache.config.LRUCacheConfiguration) XWikiException(com.xpn.xwiki.XWikiException) LRUCacheConfiguration(org.xwiki.cache.config.LRUCacheConfiguration)

Example 2 with CacheConfiguration

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

the class DefaultLESSResourcesCacheTest method setUp.

@Before
public void setUp() throws Exception {
    cacheManager = mocker.getInstance(CacheManager.class);
    cache = mock(Cache.class);
    CacheFactory cacheFactory = mock(CacheFactory.class);
    when(cacheManager.getCacheFactory()).thenReturn(cacheFactory);
    CacheConfiguration configuration = new CacheConfiguration("lesscss.skinfiles.cache");
    when(cacheFactory.<String>newCache(eq(configuration))).thenReturn(cache);
    cacheKeyFactory = mocker.getInstance(CacheKeyFactory.class);
    LESSSkinFileResourceReference lessSkinFileResourceReference = new LESSSkinFileResourceReference("lessResource", null, null);
    when(cacheKeyFactory.getCacheKey(eq(lessSkinFileResourceReference), eq(new FSSkinReference("skin")), eq(new NamedColorThemeReference("colorTheme")), eq(true))).thenReturn("12_lessResource_4_skin_10_colorTheme");
}
Also used : NamedColorThemeReference(org.xwiki.lesscss.internal.colortheme.NamedColorThemeReference) CacheManager(org.xwiki.cache.CacheManager) FSSkinReference(org.xwiki.lesscss.internal.skin.FSSkinReference) CacheFactory(org.xwiki.cache.CacheFactory) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) Cache(org.xwiki.cache.Cache) LESSSkinFileResourceReference(org.xwiki.lesscss.internal.resources.LESSSkinFileResourceReference) Before(org.junit.Before)

Example 3 with CacheConfiguration

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

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

the class DefaultIconSetCacheTest method setUp.

@Before
public void setUp() throws Exception {
    cacheManager = mocker.getInstance(CacheManager.class);
    entityReferenceSerializer = mocker.getInstance(new DefaultParameterizedType(null, EntityReferenceSerializer.class, String.class));
    cache = mock(Cache.class);
    CacheFactory cacheFactory = mock(CacheFactory.class);
    when(cacheManager.getCacheFactory()).thenReturn(cacheFactory);
    CacheConfiguration configuration = new CacheConfiguration("iconset");
    when(cacheFactory.<IconSet>newCache(eq(configuration))).thenReturn(cache);
}
Also used : CacheManager(org.xwiki.cache.CacheManager) DefaultParameterizedType(org.xwiki.component.util.DefaultParameterizedType) CacheFactory(org.xwiki.cache.CacheFactory) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) Cache(org.xwiki.cache.Cache) IconSet(org.xwiki.icon.IconSet) Before(org.junit.Before)

Example 5 with CacheConfiguration

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

the class DefaultDocumentCache method create.

@Override
public void create(CacheConfiguration cacheConfiguration) throws CacheException {
    this.name = cacheConfiguration.getConfigurationId();
    this.cache = this.cacheManager.createNewCache(cacheConfiguration);
    CacheConfiguration mappingCacheConfiguration = (CacheConfiguration) cacheConfiguration.clone();
    mappingCacheConfiguration.setConfigurationId(cacheConfiguration.getConfigurationId() + ".mapping");
    this.mappingCache = this.cacheManager.createNewCache(mappingCacheConfiguration);
    this.observationManager.addListener(this.listener);
}
Also used : 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