C - The native cache implementationpublic interface SyncCache<C> extends Cache<C>
A synchronous API for accessing cache values that is useful for in-memory caching implementations.
Caching implementations that require blocking IO should implement the getExecutorService() method to provide an
executor service to offload the operations to. If the cache natively supports asynchronous operations, override the async() method to provide a more customized asynchronous solution.
Implementers of this interface should mark the implementation as Blocking if a blocking operation is
required to read or write cache values
Cache,
AsyncCache| Modifier and Type | Method and Description |
|---|---|
default AsyncCache<C> |
async()
This method returns an async version of this cache interface implementation.
|
<T> 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> 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.Optional<T> |
get(java.lang.Object key,
java.lang.Class<T> requiredType)
Resolve the given value for the given key.
|
default <T> 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.
|
default java.util.concurrent.ExecutorService |
getExecutorService() |
void |
invalidate(java.lang.Object key)
Invalidate the value for the given key.
|
void |
invalidateAll()
Invalidate all cached values within this cache.
|
void |
put(java.lang.Object key,
java.lang.Object value)
Cache the specified value using the specified key.
|
default <T> T |
putIfAbsent(java.lang.Object key,
java.util.function.Supplier<T> value)
Cache the supplied value using the specified key if it is not already present.
|
<T> 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.
|
getCacheInfo, getName, getNativeCache@NonNull
<T> java.util.Optional<T> get(@NonNull
java.lang.Object key,
@NonNull
io.micronaut.core.type.Argument<T> requiredType)
T - The concrete typekey - The cache keyrequiredType - The required type<T> T get(@NonNull
java.lang.Object key,
@NonNull
io.micronaut.core.type.Argument<T> requiredType,
@NonNull
java.util.function.Supplier<T> supplier)
Supplier will
be invoked and the return value cached.T - The concrete typekey - The cache keyrequiredType - The required typesupplier - The supplier that should be invoked if the value is not found@NonNull
<T> java.util.Optional<T> putIfAbsent(@NonNull
java.lang.Object key,
@NonNull
T value)
Cache the specified value using the specified key if it is not already present.
T - The concrete typekey - the key with which the specified value is to be associatedvalue - the value to be associated with the specified keyOptional.empty() if the specified value parameter was cached@NonNull
default <T> T putIfAbsent(@NonNull
java.lang.Object key,
@NonNull
java.util.function.Supplier<T> value)
Cache the supplied value using the specified key if it is not already present.
T - The concrete typekey - the key with which the specified value is to be associatedvalue - the value supplier to be associated with the specified keyvoid put(@NonNull
java.lang.Object key,
@NonNull
java.lang.Object value)
Cache the specified value using the specified key.
key - the key with which the specified value is to be associatedvalue - the value to be associated with the specified keyvoid invalidate(@NonNull
java.lang.Object key)
key - The key to invalidvoid invalidateAll()
default <T> T get(@NonNull
java.lang.Object key,
@NonNull
java.lang.Class<T> requiredType,
@NonNull
java.util.function.Supplier<T> supplier)
Supplier will
be invoked and the return value cached.T - The concrete typekey - The cache keyrequiredType - The required typesupplier - The supplier that should be invoked if the value is not found@NonNull
default <T> java.util.Optional<T> get(@NonNull
java.lang.Object key,
@NonNull
java.lang.Class<T> requiredType)
T - The concrete typekey - The cache keyrequiredType - The required type@Nullable default java.util.concurrent.ExecutorService getExecutorService()
@NonNull default AsyncCache<C> async()
This method returns an async version of this cache interface implementation.
The default behaviour will execute the operations in the same thread if null
is returned from getExecutorService(). If an executor service is returned, the
operations will be offloaded to the provided executor service.
AsyncCache implementation for this cache