Package io.micronaut.cache
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 java.lang.Object implements AsyncCache<C>
An asynchronous cache that delegates blocking cache operations to the provided executor.- Since:
- 1.3.0
-
-
Constructor Summary
Constructors Constructor Description DelegatingAsyncCache(SyncCache<C> delegate, java.util.concurrent.ExecutorService executorService)
-
Method Summary
All Methods Instance Methods Concrete 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.java.lang.StringgetName()CgetNativeCache()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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.micronaut.cache.AsyncCache
get, get
-
Methods inherited from interface io.micronaut.cache.Cache
getCacheInfo
-
-
-
-
Method Detail
-
get
public <T> java.util.concurrent.CompletableFuture<java.util.Optional<T>> get(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType)Description copied from interface:AsyncCacheResolve the given value for the given key.- Specified by:
getin interfaceAsyncCache<C>- Type Parameters:
T- The concrete type- Parameters:
key- The cache keyrequiredType- 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> java.util.concurrent.CompletableFuture<T> get(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType, java.util.function.Supplier<T> supplier)Description copied from interface:AsyncCacheResolve the given value for the given key. If the value is not found the specifiedSupplierwill be invoked and the return value cached.- Specified by:
getin interfaceAsyncCache<C>- Type Parameters:
T- The concrete type- Parameters:
key- The cache keyrequiredType- The required typesupplier- 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> java.util.concurrent.CompletableFuture<java.util.Optional<T>> putIfAbsent(java.lang.Object key, T value)Description copied from interface:AsyncCacheCache the specified value using the specified key if it is not already present.
- Specified by:
putIfAbsentin interfaceAsyncCache<C>- Type Parameters:
T- The concrete type- Parameters:
key- The key with which the specified value is to be associatedvalue- 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 java.lang.String getName()
-
getNativeCache
public C getNativeCache()
- Specified by:
getNativeCachein interfaceCache<C>- Returns:
- The native cache implementation
-
put
public java.util.concurrent.CompletableFuture<java.lang.Boolean> put(java.lang.Object key, java.lang.Object value)Description copied from interface:AsyncCacheCache the specified value using the specified key.
- Specified by:
putin interfaceAsyncCache<C>- Parameters:
key- The key with which the specified value is to be associatedvalue- 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 java.util.concurrent.CompletableFuture<java.lang.Boolean> invalidate(java.lang.Object key)
Description copied from interface:AsyncCacheInvalidate the value for the given key.- Specified by:
invalidatein interfaceAsyncCache<C>- Parameters:
key- The key to invalid- Returns:
- A future with a boolean indicating whether the operation was succesful or not
-
invalidateAll
public java.util.concurrent.CompletableFuture<java.lang.Boolean> invalidateAll()
Description copied from interface:AsyncCacheInvalidate all cached values within this cache.- Specified by:
invalidateAllin interfaceAsyncCache<C>- Returns:
- A future with a boolean indicating whether the operation was succesful or not
-
-