Class CaffeineCacheProvider<K,V>

java.lang.Object
org.springframework.pulsar.cache.provider.caffeine.CaffeineCacheProvider<K,V>
Type Parameters:
K - the type of cache key
V - the type of cache entries
All Implemented Interfaces:
CacheProvider<K,V>

public class CaffeineCacheProvider<K,V> extends Object implements CacheProvider<K,V>
Cache provider implementation backed by a Caffeine cache.
Author:
Chris Bono
  • Constructor Details

    • CaffeineCacheProvider

      public CaffeineCacheProvider(com.github.benmanes.caffeine.cache.Cache<K,V> cache)
  • Method Details

    • getOrCreateIfAbsent

      public V getOrCreateIfAbsent(K cacheKey, Function<K,V> createEntryFunction)
      Description copied from interface: CacheProvider
      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.

      Specified by:
      getOrCreateIfAbsent in interface CacheProvider<K,V>
      Parameters:
      cacheKey - 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

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

      public void invalidateAll(BiConsumer<K,V> onInvalidateEntry)
      Description copied from interface: CacheProvider
      Discards all entries in the cache and calls the onInvalidateEntry callback (if provided) for each entry.
      Specified by:
      invalidateAll in interface CacheProvider<K,V>
      Parameters:
      onInvalidateEntry - callback invoked for each invalidated entry