public StandardCache(final String name, final boolean useSoftReferences, final int initialCapacity, final int maxSize, final ICacheEntryValidityChecker<? super K, ? super V> entryValidityChecker, final Logger logger, final boolean enableCounters) { super(); Validate.notEmpty(name, "Name cannot be null or empty"); Validate.isTrue(initialCapacity > 0, "Initial capacity must be > 0"); Validate.isTrue(maxSize != 0, "Cache max size must be either -1 (no limit) or > 0"); this.name = name; this.useSoftReferences = useSoftReferences; this.maxSize = maxSize; this.entryValidityChecker = entryValidityChecker; this.logger = logger; this.traceExecution = (logger != null && logger.isTraceEnabled()); this.enableCounters = (this.traceExecution || enableCounters); this.dataContainer = new CacheDataContainer<K,V>(this.name, initialCapacity, maxSize, this.traceExecution, this.logger); this.getCount = new AtomicLong(0); this.putCount = new AtomicLong(0); this.hitCount = new AtomicLong(0); this.missCount = new AtomicLong(0); if (this.logger != null) { if (this.maxSize < 0) { this.logger.trace("[THYMELEAF][CACHE_INITIALIZE] Initializing cache {}. Soft references {}.", this.name, (this.useSoftReferences? "are used" : "not used")); } else { this.logger.trace("[THYMELEAF][CACHE_INITIALIZE] Initializing cache {}. Max size: {}. Soft references {}.", new Object[] {this.name, Integer.valueOf(this.maxSize), (this.useSoftReferences? "are used" : "not used")}); } } }
public void clear() { this.dataContainer.clear(); if (this.traceExecution) { this.logger.trace( "[THYMELEAF][{}][*][{}][CACHE_REMOVE][0] Removing ALL cache entries in cache \"{}\". New size is 0.", new Object[] {TemplateEngine.threadIndex(), this.name, this.name}); } }
public V get(final K key, final ICacheEntryValidityChecker<? super K, ? super V> validityChecker) { final CacheEntry<V> resultEntry = this.dataContainer.get(key); resultEntry.getValueIfStillValid(this.name, key, validityChecker, this.traceExecution, this.logger); if (resultValue == null) { final int newSize = this.dataContainer.remove(key); incrementReportEntity(this.missCount); if (this.traceExecution) {
new CacheDataContainer<K,V>(this.name, initialCapacity, maxSize, this.traceExecution, this.logger);
public int size() { return this.dataContainer.size(); }
public void clearKey(final K key) { final int newSize = this.dataContainer.remove(key); if (this.traceExecution && newSize != -1) { this.logger.trace( "[THYMELEAF][{}][*][{}][CACHE_REMOVE][{}] Removed cache entry in cache \"{}\" for key \"{}\". New size is {}.", new Object[] {TemplateEngine.threadIndex(), this.name, Integer.valueOf(newSize), this.name, key, Integer.valueOf(newSize)}); } }
public void clear() { this.dataContainer.clear(); if (this.traceExecution) { this.logger.trace( "[THYMELEAF][{}][*][{}][CACHE_REMOVE][0] Removing ALL cache entries in cache \"{}\". New size is 0.", new Object[] {TemplateEngine.threadIndex(), this.name, this.name}); } }
public int put(final K key, final CacheEntry<V> value) { if (this.traceExecution) { return putWithTracing(key, value); } return putWithoutTracing(key, value); }
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(); }
public int remove(final K key) { if (this.traceExecution) { return removeWithTracing(key); } return removeWithoutTracing(key); }
public int size() { return this.dataContainer.size(); }
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(); } }
public void clearKey(final K key) { final int newSize = this.dataContainer.remove(key); if (this.traceExecution && newSize != -1) { this.logger.trace( "[THYMELEAF][{}][*][{}][CACHE_REMOVE][{}] Removed cache entry in cache \"{}\" for key \"{}\". New size is {}.", new Object[] {TemplateEngine.threadIndex(), this.name, Integer.valueOf(newSize), this.name, key, Integer.valueOf(newSize)}); } }
public int remove(final K key) { if (this.traceExecution) { return removeWithTracing(key); } return removeWithoutTracing(key); }
public int put(final K key, final CacheEntry<V> value) { if (this.traceExecution) { return putWithTracing(key, value); } return putWithoutTracing(key, value); }