Class StandardCache<K,V>

java.lang.Object
org.thymeleaf.cache.StandardCache<K,V>
Type Parameters:
K - The type of the cache keys
V - The type of the cache values
All Implemented Interfaces:
ICache<K,V>

public final class StandardCache<K,V> extends Object implements ICache<K,V>
Since:
2.0.0
  • Field Details

    • REPORT_INTERVAL

      private static final long REPORT_INTERVAL
      See Also:
    • REPORT_FORMAT

      private static final String REPORT_FORMAT
      See Also:
    • lastExecution

      private volatile long lastExecution
    • name

      private final String name
    • useSoftReferences

      private final boolean useSoftReferences
    • maxSize

      private final int maxSize
    • dataContainer

      private final StandardCache.CacheDataContainer<K,V> dataContainer
    • entryValidityChecker

      private final ICacheEntryValidityChecker<? super K,? super V> entryValidityChecker
    • traceExecution

      private final boolean traceExecution
    • enableCounters

      private final boolean enableCounters
    • logger

      private final org.slf4j.Logger logger
    • getCount

      private final AtomicLong getCount
    • putCount

      private final AtomicLong putCount
    • hitCount

      private final AtomicLong hitCount
    • missCount

      private final AtomicLong missCount
  • Constructor Details

    • StandardCache

      public StandardCache(String name, boolean useSoftReferences, int initialCapacity, org.slf4j.Logger logger)
    • StandardCache

      public StandardCache(String name, boolean useSoftReferences, int initialCapacity, ICacheEntryValidityChecker<? super K,? super V> entryValidityChecker, org.slf4j.Logger logger)
    • StandardCache

      public StandardCache(String name, boolean useSoftReferences, int initialCapacity, int maxSize, org.slf4j.Logger logger)
    • StandardCache

      public StandardCache(String name, boolean useSoftReferences, int initialCapacity, int maxSize, ICacheEntryValidityChecker<? super K,? super V> entryValidityChecker, org.slf4j.Logger logger)
    • StandardCache

      public StandardCache(String name, boolean useSoftReferences, int initialCapacity, int maxSize, ICacheEntryValidityChecker<? super K,? super V> entryValidityChecker, org.slf4j.Logger logger, boolean enableCounters)
  • Method Details

    • put

      public void put(K key, V value)
      Description copied from interface: ICache

      Insert a new value into the cache.

      Specified by:
      put in interface ICache<K,V>
      Parameters:
      key - the key of the new entry
      value - the value to be cached
    • get

      public V get(K key)
      Description copied from interface: ICache

      Retrieve a value from the cache.

      Specified by:
      get in interface ICache<K,V>
      Parameters:
      key - the key of the value to be retrieved
      Returns:
      the retrieved value, or null if no value exists for the specified key.
    • get

      public V get(K key, ICacheEntryValidityChecker<? super K,? super V> validityChecker)
      Description copied from interface: ICache

      Retrieve a value from the cache, using the specified validity checker to ensure the entry is still valid. If the cache already has a default validity checker, this method should override this setting and use the one specified instead.

      Specified by:
      get in interface ICache<K,V>
      Parameters:
      key - the key of the value to be retrieved
      validityChecker - the validity checker to be used to ensure the entry is still valid.
      Returns:
      the retrieved value, or null if no value exists for the specified key.
    • keySet

      public Set<K> keySet()

      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 get(Object) for these keys might be null.

      Specified by:
      keySet in interface ICache<K,V>
      Returns:
      the complete set of cache keys. Might include keys for already-invalid (non-cleaned) entries.
      Since:
      2.1.4
    • clear

      public void clear()
      Description copied from interface: ICache

      Clear the entire cache.

      Specified by:
      clear in interface ICache<K,V>
    • clearKey

      public void clearKey(K key)
      Description copied from interface: ICache

      Clears a specific entry in the cache.

      Specified by:
      clearKey in interface ICache<K,V>
      Parameters:
      key - the key of the entry to be cleared.
    • getName

      public String getName()
    • hasMaxSize

      public boolean hasMaxSize()
    • getMaxSize

      public int getMaxSize()
    • getUseSoftReferences

      public boolean getUseSoftReferences()
    • size

      public int size()
    • getPutCount

      public long getPutCount()
    • getGetCount

      public long getGetCount()
    • getHitCount

      public long getHitCount()
    • getMissCount

      public long getMissCount()
    • getHitRatio

      public double getHitRatio()
    • getMissRatio

      public double getMissRatio()
    • incrementReportEntity

      private void incrementReportEntity(AtomicLong entity)
    • outputReportIfNeeded

      private void outputReportIfNeeded()