Class CaffeineCacheImpl

  • All Implemented Interfaces:
    Cache, CaffeineCache

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

      • cache

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

      • CaffeineCacheImpl

        public CaffeineCacheImpl​(CaffeineCacheInfo cacheInfo,
                                 boolean recordStats)
    • Method Detail

      • 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
      • 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
      • replaceUniValue

        public io.smallrye.mutiny.Uni<Void> replaceUniValue​(Object key,
                                                            Object emittedValue)
        Description copied from class: AbstractCache
        Replaces the cache value associated with the given key by an item emitted by a Uni. This method can be called several times for the same key, each call will then always replace the existing cache entry with the given emitted value. If the key no longer identifies a cache entry, this method must not put the emitted item into the cache.
        Specified by:
        replaceUniValue in class AbstractCache
      • 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
      • getSize

        public long getSize()