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);
}
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);
}
}
}
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);
}
}
}
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);
}
}
Aggregations