Class CaffeineCacheImpl

java.lang.Object
io.quarkus.cache.runtime.AbstractCache
io.quarkus.cache.runtime.caffeine.CaffeineCacheImpl
All Implemented Interfaces:
Cache, CaffeineCache

public class CaffeineCacheImpl extends AbstractCache implements CaffeineCache
This class is an internal Quarkus cache implementation using Caffeine. Do not use it explicitly from your Quarkus application. The public methods signatures may change without prior notice.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) final com.github.benmanes.caffeine.cache.AsyncCache<Object,Object>
     

    Fields inherited from class io.quarkus.cache.runtime.AbstractCache

    NULL_KEYS_NOT_SUPPORTED_MSG
  • Constructor Summary

    Constructors
    Constructor
    Description
    CaffeineCacheImpl(CaffeineCacheInfo cacheInfo, boolean recordStats)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    <K, V> io.smallrye.mutiny.Uni<V>
    get(K key, Function<K,V> valueLoader)
    Returns a lazy asynchronous action that will emit the cache value identified by key, obtaining that value from valueLoader if necessary.
    <K, V> io.smallrye.mutiny.Uni<V>
    getAsync(K key, Function<K,io.smallrye.mutiny.Uni<V>> valueLoader)
    Returns a lazy asynchronous action that will emit the cache value identified by key, obtaining that value from valueLoader if necessary.
     
    Returns the future associated with key in this cache, or null if there is no cached future for key.
    Returns the cache name.
    long
     
    io.smallrye.mutiny.Uni<Void>
    Removes the cache entry identified by key from the cache.
    io.smallrye.mutiny.Uni<Void>
    Removes all entries from the cache.
    io.smallrye.mutiny.Uni<Void>
    Removes all cache entries whose keys match the given predicate.
    Returns an unmodifiable Set view of the keys contained in this cache.
    <V> void
    put(Object key, CompletableFuture<V> valueFuture)
    Associates value with key in this cache.
    void
    Changes the duration, initially set from the configuration, after which each entry should be automatically removed from the cache once that duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read.
    void
    Changes the duration, initially set from the configuration, after which each entry should be automatically removed from the cache once that duration has elapsed after the entry's creation, or the most recent replacement of its value.
    void
    setMaximumSize(long maximumSize)
    Changes the maximum number of entries the cache may contain.

    Methods inherited from class io.quarkus.cache.runtime.AbstractCache

    as, getDefaultKey

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.quarkus.cache.Cache

    as, getDefaultKey
  • Field Details

    • cache

      final com.github.benmanes.caffeine.cache.AsyncCache<Object,Object> cache
  • Constructor Details

    • CaffeineCacheImpl

      public CaffeineCacheImpl(CaffeineCacheInfo cacheInfo, boolean recordStats)
  • Method Details

    • getName

      public String getName()
      Description copied from interface: Cache
      Returns the cache name.
      Specified by:
      getName in interface Cache
      Returns:
      cache name
    • get

      public <K, V> io.smallrye.mutiny.Uni<V> get(K key, Function<K,V> valueLoader)
      Description copied from interface: Cache
      Returns a lazy asynchronous action that will emit the cache value identified by key, obtaining that value from valueLoader if necessary.
      Specified by:
      get in interface Cache
      Type Parameters:
      K - cache key type
      V - cache value type
      Parameters:
      key - cache key
      valueLoader - function used to compute a cache value if key is not already associated with a value
      Returns:
      a lazy asynchronous action that will emit a cache value
    • getAsync

      public <K, V> io.smallrye.mutiny.Uni<V> getAsync(K key, Function<K,io.smallrye.mutiny.Uni<V>> valueLoader)
      Description copied from interface: Cache
      Returns a lazy asynchronous action that will emit the cache value identified by key, obtaining that value from valueLoader if necessary.
      Specified by:
      getAsync in interface Cache
      Type Parameters:
      K -
      V -
      Parameters:
      key -
      valueLoader -
      Returns:
      a lazy asynchronous action that will emit a cache value
    • getIfPresent

      public <V> CompletableFuture<V> getIfPresent(Object key)
      Description copied from interface: CaffeineCache
      Returns the future associated with key in this cache, or null if there is no cached future for key. This method is delegating to the AsyncCache.getIfPresent(Object), while recording the cache stats if they are enabled.
      Specified by:
      getIfPresent in interface CaffeineCache
      Parameters:
      key - key whose associated value is to be returned
      Returns:
      the future value to which the specified key is mapped, or null if this cache does not contain a mapping for the key
      See Also:
      • AsyncCache.getIfPresent(Object)
    • invalidate

      public io.smallrye.mutiny.Uni<Void> invalidate(Object key)
      Description copied from interface: Cache
      Removes the cache entry identified by key from the cache. If the key does not identify any cache entry, nothing will happen.
      Specified by:
      invalidate in interface Cache
      Parameters:
      key - cache key
    • invalidateAll

      public io.smallrye.mutiny.Uni<Void> invalidateAll()
      Description copied from interface: Cache
      Removes all entries from the cache.
      Specified by:
      invalidateAll in interface Cache
    • invalidateIf

      public io.smallrye.mutiny.Uni<Void> invalidateIf(Predicate<Object> predicate)
      Description copied from interface: Cache
      Removes all cache entries whose keys match the given predicate.
      Specified by:
      invalidateIf in interface Cache
      Parameters:
      predicate -
    • keySet

      public Set<Object> keySet()
      Description copied from interface: CaffeineCache
      Returns an unmodifiable Set view of the keys contained in this cache. If the cache entries are modified while an iteration over the set is in progress, the set will remain unchanged.
      Specified by:
      keySet in interface CaffeineCache
      Returns:
      a set view of the keys contained in this cache
    • put

      public <V> void put(Object key, CompletableFuture<V> valueFuture)
      Description copied from interface: CaffeineCache
      Associates value with key in this cache. If the cache previously contained a value associated with key, the old value is replaced by value. If the asynchronous computation fails, the entry will be automatically removed.

      Prefer Cache.get(Object, Function) when using the conventional "if cached, return; otherwise create, cache and return" pattern.

      Specified by:
      put in interface CaffeineCache
      Parameters:
      key - key with which the specified value is to be associated
      valueFuture - value to be associated with the specified key
    • setExpireAfterWrite

      public void setExpireAfterWrite(Duration duration)
      Description copied from interface: CaffeineCache
      Changes the duration, initially set from the configuration, after which each entry should be automatically removed from the cache once that duration has elapsed after the entry's creation, or the most recent replacement of its value.

      Warning: this method must not be invoked from within an atomic scope of a cache operation.

      Specified by:
      setExpireAfterWrite in interface CaffeineCache
      Parameters:
      duration - the length of time after which an entry should be automatically removed
    • setExpireAfterAccess

      public void setExpireAfterAccess(Duration duration)
      Description copied from interface: CaffeineCache
      Changes the duration, initially set from the configuration, after which each entry should be automatically removed from the cache once that duration has elapsed after the entry's creation, the most recent replacement of its value, or its last read.

      Warning: this method must not be invoked from within an atomic scope of a cache operation.

      Specified by:
      setExpireAfterAccess in interface CaffeineCache
      Parameters:
      duration - the length of time after which an entry should be automatically removed
    • setMaximumSize

      public void setMaximumSize(long maximumSize)
      Description copied from interface: CaffeineCache
      Changes the maximum number of entries the cache may contain.

      Warning: this method must not be invoked from within an atomic scope of a cache operation.

      Specified by:
      setMaximumSize in interface CaffeineCache
      Parameters:
      maximumSize - the maximum size of the cache
    • getCacheInfo

      public CaffeineCacheInfo getCacheInfo()
    • getSize

      public long getSize()