/** * Dispose the value being removed from the cache. * * @param value the value to dispose */ protected void disposeCacheValue(T value) { if (value instanceof DisposableCacheValue) { try { ((DisposableCacheValue) value).dispose(); } catch (Throwable e) { LOGGER.warn("Error when trying to dispose a cache object of cache [{}]", this.configuration.getConfigurationId(), e); } } } }
/** * Dispose the value being removed from the cache. * * @param value the value to dispose */ protected void disposeCacheValue(T value) { if (value instanceof DisposableCacheValue) { try { ((DisposableCacheValue) value).dispose(); } catch (Throwable e) { // We catch Throwable because this method is usually automatically called by an event send by the cache // implementation and there is no reason to crash the whole cache because of some badly implemented // dispose() we don't control. LOGGER.warn("Error when trying to dispose a cache object of cache [{}]", this.configuration != null ? this.configuration.getConfigurationId() : null, e); } } } }
/** * @return the path of the temporary local folder based on configuration identifier */ protected String createTempDir() { String path = (String) this.configuration.get(CONFX_CACHE_PATH); if (path == null) { File file; if (this.environment != null) { file = new File(this.environment.getTemporaryDirectory().getAbsolutePath(), "cache"); } else { file = new File(System.getProperty("java.io.tmpdir"), "xwiki"); } if (this.configuration.getConfigurationId() == null) { file = new File(file, this.configuration.getConfigurationId()); } if (!file.exists()) { file.mkdirs(); } path = file.getAbsolutePath(); } return path; }
/** * @return the path of the temporary local folder based on configuration identifier */ protected String createTempDir() { String path = (String) this.configuration.get(CONFX_CACHE_PATH); if (path == null) { File file; if (this.environment != null) { file = new File(this.environment.getTemporaryDirectory().getAbsolutePath(), "cache"); } else { file = new File(System.getProperty("java.io.tmpdir"), "xwiki"); } if (this.configuration.getConfigurationId() == null) { file = new File(file, this.configuration.getConfigurationId()); } if (!file.exists()) { file.mkdirs(); } path = file.getAbsolutePath(); } return path; }
private Cache<DefaultWikiDescriptor> createCache(String cacheId) throws InitializationException { CacheConfiguration configuration = new CacheConfiguration(cacheId); try { return this.cacheManager.createNewCache(configuration); } catch (CacheException e) { throw new InitializationException( String.format("Failed to initialize wiki descriptor caches [%s]", configuration.getConfigurationId()), e); } }
/** * {@inheritDoc} * * @see com.xpn.xwiki.internal.cache.DocumentCache#create(org.xwiki.cache.config.CacheConfiguration) */ 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(cacheConfiguration); this.observationManager.addListener(this.listener); }
/** * Get the cache with the provided name for a particular LDAP server. * * @param configuration the configuration to use to create the cache and to find it if it's already created. * @param context the XWiki context. * @return the cache. * @throws CacheException error when creating the cache. */ public Cache<Map<String, String>> getCache(CacheConfiguration configuration, XWikiContext context) throws CacheException { Cache<Map<String, String>> cache; String cacheKey = getUidAttributeName() + "." + this.connection.getConnection().getHost() + ":" + this.connection.getConnection().getPort(); Map<String, Cache<Map<String, String>>> cacheMap; if (cachePool.containsKey(cacheKey)) { cacheMap = cachePool.get(cacheKey); } else { cacheMap = new HashMap<String, Cache<Map<String, String>>>(); cachePool.put(cacheKey, cacheMap); } cache = cacheMap.get(configuration.getConfigurationId()); if (cache == null) { cache = Utils.getComponent(CacheManager.class).createNewCache(configuration); cacheMap.put(configuration.getConfigurationId(), cache); } return cache; }
cache = cacheMap.get(configuration.getConfigurationId()); cacheMap.put(configuration.getConfigurationId(), cache);
File imgTempDir = new File(tempDir, configuration.getConfigurationId()); try { imgTempDir.mkdirs();
@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); }