Interface CacheLoader<K,V>

Type Parameters:
K - key type (must be non-null)
V - value type (must be non-null)
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface CacheLoader<K,V>
Functional interface for loading values in cache-aside pattern.

Implementations should load a value from an upstream source (database, API, etc.) when the cache experiences a miss. Loaders are responsible for returning non-null values.

Thread Safety

Implementations must be thread-safe as they may be called from multiple threads concurrently.
  • Method Summary

    Modifier and Type
    Method
    Description
    load(K key)
    Load a value for the given key.
  • Method Details

    • load

      V load(K key) throws Exception
      Load a value for the given key.
      Parameters:
      key - the key to load (must not be null)
      Returns:
      the loaded value (must not be null)
      Throws:
      NullPointerException - if key is null
      Exception - if loading fails