Class NonExpiringCache<K,​V>

  • Type Parameters:
    K - The type of the key to retrieve the cached object
    V - The type of the object to cache

    public class NonExpiringCache<K,​V>
    extends Object

    Allows the Caching of an object. The object will be retrieved from the cache, or calculated using a computation function then retrieved from the cache for future retrievals.

    This cache implementation has no mechanism for evicting or expiring single entries and as such will continue to grow as new records are added. If the application is expected to have a large cache that is in need of expiry features, or per record eviction, it is better to use a more fully featured cache implementation such as the one provided by guava.

    • Constructor Detail

      • NonExpiringCache

        public NonExpiringCache()
    • Method Detail

      • get

        public V get​(K key,
                     Function<K,​V> valueCalculator)
        Gets the object from the cache for the given key, or computes the value from calculation function and inserts the calculated value into the map.
        Parameters:
        key - The key of the object to retrieve
        valueCalculator - The function to calculate the value if the key is not in the cache
        Returns:
        The object for the given key. The object will come from the cache if it is already in the cache, or from the value calculation function. If the value is calculated it will be inserted into the cache and subsequent retrievals will get the value from the cache.
      • clear

        public void clear()
        Clears the cache.
      • size

        public int size()
        Gets the size of the cache.
        Returns:
        the size of the cache.