Class CacheBase<K,​V,​D>

  • Type Parameters:
    K - Cache lookup key type
    V - Cache instance value type
    D - Data type for creating a new instance value
    Direct Known Subclasses:
    SoftCache

    public abstract class CacheBase<K,​V,​D>
    extends java.lang.Object
    Base class for cache implementations. To use, instantiate a subclass of a concrete implementation class, where the subclass implements the createInstance() method, and call get() with the key and the data. The get() call will use the data only if it needs to call createInstance(), otherwise the data is ignored.
    • Constructor Summary

      Constructors 
      Constructor Description
      CacheBase()  
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      protected abstract V createInstance​(K key, D data)
      Creates an instance for the key and data.
      abstract V getInstance​(K key, D data)
      Retrieves an instance from the cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CacheBase

        public CacheBase()
    • Method Detail

      • getInstance

        public abstract V getInstance​(K key,
                                      D data)
        Retrieves an instance from the cache. Calls createInstance(key, data) if the cache does not already contain an instance with this key. Ignores data if the cache already contains an instance with this key.
        Parameters:
        key - Cache lookup key for the requested instance
        data - Data for createInstance() if the instance is not already cached
        Returns:
        The requested instance
      • createInstance

        protected abstract V createInstance​(K key,
                                            D data)
        Creates an instance for the key and data. Must be overridden.
        Parameters:
        key - Cache lookup key for the requested instance
        data - Data for the instance creation
        Returns:
        The requested instance