@Override protected final ICache<ExpressionCacheKey, Object> initializeExpressionCache() { final int maxSize = getExpressionCacheMaxSize(); if (maxSize == 0) { return null; } return new StandardCache<ExpressionCacheKey, Object>( getExpressionCacheName(), getExpressionCacheUseSoftReferences(), getExpressionCacheInitialSize(), maxSize, getExpressionCacheValidityChecker(), getExpressionCacheLogger(), getExpressionCacheEnableCounters()); }
@Override protected final ICache<TemplateCacheKey, TemplateModel> initializeTemplateCache() { final int maxSize = getTemplateCacheMaxSize(); if (maxSize == 0) { return null; } return new StandardCache<TemplateCacheKey, TemplateModel>( getTemplateCacheName(), getTemplateCacheUseSoftReferences(), getTemplateCacheInitialSize(), maxSize, getTemplateCacheValidityChecker(), getTemplateCacheLogger(), getTemplateCacheEnableCounters()); }
public double getHitRatio() { long hitCount = getHitCount(); long getCount = getGetCount(); if (hitCount == 0 || getCount == 0) { return 0; } return (double) hitCount / (double) getCount; }
static Object getFromCache(final IEngineConfiguration configuration, final String input, final String type) { final ICacheManager cacheManager = configuration.getCacheManager(); if (cacheManager != null) { final ICache<ExpressionCacheKey,Object> cache = cacheManager.getExpressionCache(); if (cache != null) { return cache.get(new ExpressionCacheKey(type,input)); } } return null; }
static <V> void putIntoCache(final IEngineConfiguration configuration, final String input, final V value, final String type) { final ICacheManager cacheManager = configuration.getCacheManager(); if (cacheManager != null) { final ICache<ExpressionCacheKey,Object> cache = cacheManager.getExpressionCache(); if (cache != null) { cache.put(new ExpressionCacheKey(type,input), value); } } }
static <V> void removeFromCache(final IEngineConfiguration configuration, final String input, final String type) { final ICacheManager cacheManager = configuration.getCacheManager(); if (cacheManager != null) { final ICache<ExpressionCacheKey,Object> cache = cacheManager.getExpressionCache(); if (cache != null) { cache.clearKey(new ExpressionCacheKey(type,input)); } } }
public void clearAllCaches() { final ICache<TemplateCacheKey, TemplateModel> templateCacheObj = getTemplateCache(); if (templateCacheObj != null) { templateCacheObj.clear(); } final ICache<ExpressionCacheKey, Object> expressionCacheObj = getExpressionCache(); if (expressionCacheObj != null) { expressionCacheObj.clear(); } final List<String> allSpecificCacheNamesObj = getAllSpecificCacheNames(); if (allSpecificCacheNamesObj != null) { for (final String specificCacheName : allSpecificCacheNamesObj) { final ICache<?,?> specificCache = getSpecificCache(specificCacheName); if (specificCache != null) { specificCache.clear(); } } } }
public void put(final K key, final V value) { incrementReportEntity(this.putCount); final CacheEntry<V> entry = new CacheEntry<V>(value, this.useSoftReferences); // newSize will be -1 if traceExecution is false final int newSize = this.dataContainer.put(key, entry); if (this.traceExecution) { this.logger.trace( "[THYMELEAF][{}][{}][CACHE_ADD][{}] Adding cache entry in cache \"{}\" for key \"{}\". New size is {}.", new Object[] {TemplateEngine.threadIndex(), this.name, Integer.valueOf(newSize), this.name, key, Integer.valueOf(newSize)}); outputReportIfNeeded(); } }
private static ExpressionCacheKey computeMethodCacheKey(final Class<?> targetClass, final String propertyName) { return new ExpressionCacheKey(EXPRESSION_CACHE_TYPE_OGNL_SHORTCUT, targetClass.getName(), propertyName); }
public int put(final K key, final CacheEntry<V> value) { if (this.traceExecution) { return putWithTracing(key, value); } return putWithoutTracing(key, value); }
public int remove(final K key) { if (this.traceExecution) { return removeWithTracing(key); } return removeWithoutTracing(key); }
/** * <p> * Clears the template cache. * </p> */ public void clearCaches() { if (this.templateCache != null) { this.templateCache.clear(); } }
public final ICache<TemplateCacheKey, TemplateModel> getTemplateCache() { if (!this.templateCacheInitialized) { synchronized(this) { if (!this.templateCacheInitialized) { this.templateCache = initializeTemplateCache(); this.templateCacheInitialized = true; } } } return this.templateCache; }
public final ICache<ExpressionCacheKey, Object> getExpressionCache() { if (!this.expressionCacheInitialized) { synchronized(this) { if (!this.expressionCacheInitialized) { this.expressionCache = initializeExpressionCache(); this.expressionCacheInitialized = true; } } } return this.expressionCache; }
public V get(final K key) { return get(key, this.entryValidityChecker); }
public int size() { return this.dataContainer.size(); }
/** * <p> * Returns all the keys contained in this cache. Note this method might return keys for entries * that are already invalid, so the result of calling {@link #get(Object)} for these keys might * be {@code null}. * </p> * * @return the complete set of cache keys. Might include keys for already-invalid (non-cleaned) entries. * @since 2.1.4 */ public Set<K> keySet() { return this.dataContainer.keySet(); }
public double getMissRatio() { return 1 - getHitRatio(); }
@Override protected ICacheEntryValidity computeValidity(final IEngineConfiguration configuration, final String ownerTemplate, final String template, final Map<String, Object> templateResolutionAttributes) { if (isCacheable()) { if (this.cacheTTLMs != null) { return new TTLCacheEntryValidity(this.cacheTTLMs.longValue()); } return AlwaysValidCacheEntryValidity.INSTANCE; } return NonCacheableCacheEntryValidity.INSTANCE; }
public ExpressionCacheKey(final String type, final String expression0, final String expression1) { super(); Validate.notNull(type, "Type cannot be null"); Validate.notNull(expression0, "Expression cannot be null"); this.type = type; this.expression0 = expression0; this.expression1 = expression1; // This being a cache key, its equals and hashCode methods will potentially execute many // times, so this could help performance this.h = computeHashCode(); }