Interface Cache


public interface Cache
Use this interface to interact with a cache programmatically e.g. store, retrieve or delete cache values. The cache can be injected using the @io.quarkus.cache.CacheName annotation or retrieved using CacheManager.getCache(String).
  • Method Summary

    Modifier and Type
    Method
    Description
    <T extends Cache>
    T
    as(Class<T> type)
    Returns this cache as an instance of the provided type if possible.
    <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 unique and immutable default key for the current cache.
    Returns the cache name.
    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.
  • Method Details

    • getName

      String getName()
      Returns the cache name.
      Returns:
      cache name
    • getDefaultKey

      Object getDefaultKey()
      Returns the unique and immutable default key for the current cache. This key is used by the annotations caching API when a no-args method annotated with @io.quarkus.cache.CacheResult or @io.quarkus.cache.CacheInvalidate is invoked. It can also be used with the programmatic caching API.
      Returns:
      default cache key
    • get

      <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.
      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
      Throws:
      NullPointerException - if the key is null
      CacheException - if an exception is thrown during a cache value computation
    • getAsync

      <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.
      Type Parameters:
      K -
      V -
      Parameters:
      key -
      valueLoader -
      Returns:
      a lazy asynchronous action that will emit a cache value
      Throws:
      NullPointerException - if the key is null
    • invalidate

      io.smallrye.mutiny.Uni<Void> invalidate(Object key)
      Removes the cache entry identified by key from the cache. If the key does not identify any cache entry, nothing will happen.
      Parameters:
      key - cache key
      Throws:
      NullPointerException - if the key is null
    • invalidateAll

      io.smallrye.mutiny.Uni<Void> invalidateAll()
      Removes all entries from the cache.
    • invalidateIf

      io.smallrye.mutiny.Uni<Void> invalidateIf(Predicate<Object> predicate)
      Removes all cache entries whose keys match the given predicate.
      Parameters:
      predicate -
    • as

      <T extends Cache> T as(Class<T> type)
      Returns this cache as an instance of the provided type if possible.
      Returns:
      cache instance of the provided type
      Throws:
      IllegalStateException - if this cache is not an instance of type