Class DelegatingAsyncCache<C>

java.lang.Object
io.micronaut.cache.DelegatingAsyncCache<C>
Type Parameters:
C - The cache type
All Implemented Interfaces:
AsyncCache<C>, Cache<C>

@Internal public class DelegatingAsyncCache<C> extends Object implements AsyncCache<C>
An asynchronous cache that delegates blocking cache operations to the provided executor.
Since:
1.3.0
Author:
James Kleeh
  • Constructor Details

    • DelegatingAsyncCache

      public DelegatingAsyncCache(SyncCache<C> delegate, ExecutorService executorService)
      Parameters:
      delegate - The delegate blocking cache
      executorService - The executor service to run the blocking operations on
  • Method Details

    • get

      public <T> CompletableFuture<Optional<T>> get(Object key, io.micronaut.core.type.Argument<T> requiredType)
      Description copied from interface: AsyncCache
      Resolve the given value for the given key.
      Specified by:
      get in interface AsyncCache<C>
      Type Parameters:
      T - The concrete type
      Parameters:
      key - The cache key
      requiredType - The required type
      Returns:
      An optional containing the value if it exists and is able to be converted to the specified type
    • get

      public <T> CompletableFuture<T> get(Object key, io.micronaut.core.type.Argument<T> requiredType, Supplier<T> supplier)
      Description copied from interface: AsyncCache
      Resolve the given value for the given key. If the value is not found the specified Supplier will be invoked and the return value cached.
      Specified by:
      get in interface AsyncCache<C>
      Type Parameters:
      T - The concrete type
      Parameters:
      key - The cache key
      requiredType - The required type
      supplier - The supplier that should be invoked if the value is not found
      Returns:
      An optional containing the value if it exists and is able to be converted to the specified type
    • putIfAbsent

      public <T> CompletableFuture<Optional<T>> putIfAbsent(Object key, T value)
      Description copied from interface: AsyncCache

      Cache the specified value using the specified key if it is not already present.

      Specified by:
      putIfAbsent in interface AsyncCache<C>
      Type Parameters:
      T - The concrete type
      Parameters:
      key - The key with which the specified value is to be associated
      value - The value to be associated with the specified key
      Returns:
      An optional of the existing value or Optional.empty() if the specified value parameter was cached
    • getName

      public String getName()
      Specified by:
      getName in interface Cache<C>
      Returns:
      The name of the cache
    • getNativeCache

      public C getNativeCache()
      Specified by:
      getNativeCache in interface Cache<C>
      Returns:
      The native cache implementation
    • put

      public CompletableFuture<Boolean> put(Object key, Object value)
      Description copied from interface: AsyncCache

      Cache the specified value using the specified key.

      Specified by:
      put in interface AsyncCache<C>
      Parameters:
      key - The key with which the specified value is to be associated
      value - The value to be associated with the specified key
      Returns:
      A future with a boolean indicating whether the operation was successful or not
    • invalidate

      public CompletableFuture<Boolean> invalidate(Object key)
      Description copied from interface: AsyncCache
      Invalidate the value for the given key.
      Specified by:
      invalidate in interface AsyncCache<C>
      Parameters:
      key - The key to invalid
      Returns:
      A future with a boolean indicating whether the operation was succesful or not
    • invalidateAll

      public CompletableFuture<Boolean> invalidateAll()
      Description copied from interface: AsyncCache
      Invalidate all cached values within this cache.
      Specified by:
      invalidateAll in interface AsyncCache<C>
      Returns:
      A future with a boolean indicating whether the operation was succesful or not