Interface AsyncCache<C>

  • Type Parameters:
    C - The native cache implementation
    All Superinterfaces:
    Cache<C>
    All Known Implementing Classes:
    DelegatingAsyncBlockingCache, DelegatingAsyncCache

    public interface AsyncCache<C>
    extends Cache<C>

    A cache implementation that supports async non-blocking caching operations.

    Since:
    1.0
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      <T> java.util.concurrent.CompletableFuture<java.util.Optional<T>> get​(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType)
      Resolve the given value for the given key.
      <T> java.util.concurrent.CompletableFuture<T> get​(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType, java.util.function.Supplier<T> supplier)
      Resolve the given value for the given key.
      default <T> java.util.concurrent.CompletableFuture<java.util.Optional<T>> get​(java.lang.Object key, java.lang.Class<T> requiredType)
      Resolve the given value for the given key.
      default <T> java.util.concurrent.CompletableFuture<T> get​(java.lang.Object key, java.lang.Class<T> requiredType, java.util.function.Supplier<T> supplier)
      Resolve the given value for the given key.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> invalidate​(java.lang.Object key)
      Invalidate the value for the given key.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> invalidateAll()
      Invalidate all cached values within this cache.
      java.util.concurrent.CompletableFuture<java.lang.Boolean> put​(java.lang.Object key, java.lang.Object value)
      Cache the specified value using the specified key.
      <T> java.util.concurrent.CompletableFuture<java.util.Optional<T>> putIfAbsent​(java.lang.Object key, T value)
      Cache the specified value using the specified key if it is not already present.
    • Method Detail

      • get

        <T> java.util.concurrent.CompletableFuture<java.util.Optional<T>> get​(java.lang.Object key,
                                                                              io.micronaut.core.type.Argument<T> requiredType)
        Resolve the given value for the given key.
        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

        <T> java.util.concurrent.CompletableFuture<T> get​(java.lang.Object key,
                                                          io.micronaut.core.type.Argument<T> requiredType,
                                                          java.util.function.Supplier<T> supplier)
        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.
        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

        <T> java.util.concurrent.CompletableFuture<java.util.Optional<T>> putIfAbsent​(java.lang.Object key,
                                                                                      T value)

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

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

        java.util.concurrent.CompletableFuture<java.lang.Boolean> put​(java.lang.Object key,
                                                                      java.lang.Object value)

        Cache the specified value using the specified key.

        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

        java.util.concurrent.CompletableFuture<java.lang.Boolean> invalidate​(java.lang.Object key)
        Invalidate the value for the given key.
        Parameters:
        key - The key to invalid
        Returns:
        A future with a boolean indicating whether the operation was succesful or not
      • invalidateAll

        java.util.concurrent.CompletableFuture<java.lang.Boolean> invalidateAll()
        Invalidate all cached values within this cache.
        Returns:
        A future with a boolean indicating whether the operation was succesful or not
      • get

        default <T> java.util.concurrent.CompletableFuture<java.util.Optional<T>> get​(java.lang.Object key,
                                                                                      java.lang.Class<T> requiredType)
        Resolve the given value for the given key.
        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

        default <T> java.util.concurrent.CompletableFuture<T> get​(java.lang.Object key,
                                                                  java.lang.Class<T> requiredType,
                                                                  java.util.function.Supplier<T> supplier)
        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.
        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