Interface CacheLoader<K,​V>

  • All Superinterfaces:
    Customization, DataAware<K,​V>, DataAwareCustomization<K,​V>
    All Known Subinterfaces:
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    public interface CacheLoader<K,​V>
    extends DataAwareCustomization<K,​V>
    Retrieves or generates a value to load into the cache. Using a loader to automatically populate the cache is called read through caching. If the cache is primarily used the cache data that is expensive to generate or retrieve, using a CacheLoader has several advantages. The usable features with a loader are explained in the following.

    Transparent operation: If configured, the loader is invoked implicitly, in case there is no value in the cache or it is expired, by the cache methods get(), getAll() or getEntry() as well as MutableCacheEntry.getValue().

    The cache loader can be invoked explicitly via {

    • Method Detail

      • load

        V load​(K key)
        throws Exception
        Retrieves or generates data based on the key.

        From inside this method it is illegal to call methods on the same cache. This may cause a deadlock.

        API rationale: This method declares an exception to allow any unhandled exceptions of the loader implementation to just pass through. Since the cache needs to catch an deal with loader exceptions in any way, this saves otherwise necessary try/catch clauses in the loader.

        key - the non-null key to provide the value for.
        value to be associated with the key. If the cache does not permit null values a NullPointerException is thrown, but the expiry policy is called before it.
        Exception - Unhandled exception from the loader. Exceptions are suppressed or wrapped and rethrown via a CacheLoaderException. Rethrow