Interface CacheProvider<K,V>

Type Parameters:
K - the type of cache key
V - the type of cache entries
All Known Implementing Classes:
CaffeineCacheProvider

public interface CacheProvider<K,V>
Defines the contract for a cache provider.
Author:
Chris Bono
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a view of the entries stored in the cache as a thread-safe map.
    getOrCreateIfAbsent(K key, Function<K,V> createEntryFunction)
    Returns the value associated with the key in the cache.
    void
    invalidateAll(BiConsumer<K,V> onInvalidateEntry)
    Discards all entries in the cache and calls the onInvalidateEntry callback (if provided) for each entry.
  • Method Details

    • getOrCreateIfAbsent

      V getOrCreateIfAbsent(K key, Function<K,V> createEntryFunction)
      Returns the value associated with the key in the cache.

      If the key is not already associated with an entry in the cache, the createEntryFunction is used to compute the value to cache and return.

      Parameters:
      key - the cache key
      createEntryFunction - the function to compute a value
      Returns:
      the current (existing or computed) value associated with the specified key, or null if the computed value is null
    • asMap

      Map<K,V> asMap()
      Returns a view of the entries stored in the cache as a thread-safe map. Modifications made to the map directly affect the cache.
      Returns:
      a thread-safe view of the cache supporting all optional Map operations
    • invalidateAll

      void invalidateAll(BiConsumer<K,V> onInvalidateEntry)
      Discards all entries in the cache and calls the onInvalidateEntry callback (if provided) for each entry.
      Parameters:
      onInvalidateEntry - callback invoked for each invalidated entry