Class CacheBase<K,V,D>

java.lang.Object
com.ibm.icu.impl.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 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 Details

    • CacheBase

      public CacheBase()
  • Method Details

    • 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