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> Optional<T> |
get(Object key,
io.micronaut.core.type.Argument<T> requiredType)
Resolve the given value for the given key.
|
<T> T |
get(Object key,
io.micronaut.core.type.Argument<T> requiredType,
Supplier<T> supplier)
Resolve the given value for the given key.
|
default <T> Optional<T> |
get(Object key,
Class<T> requiredType)
Resolve the given value for the given key.
|
default <T> T |
get(Object key,
Class<T> requiredType,
Supplier<T> supplier)
Resolve the given value for the given key.
|
default ExecutorService |
getExecutorService() |
void |
invalidate(Object key)
Invalidate the value for the given key.
|
void |
invalidateAll()
Invalidate all cached values within this cache.
|
void |
put(Object key,
Object value)
Cache the specified value using the specified key.
|
default <T> T |
putIfAbsent(Object key,
Supplier<T> value)
Cache the supplied value using the specified key if it is not already present.
|
<T> Optional<T> |
putIfAbsent(Object key,
T value)
Cache the specified value using the specified key if it is not already present.
|
getCacheInfo, getName, getNativeCache
@NonNull <T> Optional<T> get(@NonNull Object key, @NonNull io.micronaut.core.type.Argument<T> requiredType)
T
- The concrete typekey
- The cache keyrequiredType
- The required type<T> T get(@NonNull Object key, @NonNull io.micronaut.core.type.Argument<T> requiredType, @NonNull 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> Optional<T> putIfAbsent(@NonNull 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 Object key, @NonNull 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 Object key, @NonNull 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 Object key)
key
- The key to invalidvoid invalidateAll()
default <T> T get(@NonNull Object key, @NonNull Class<T> requiredType, @NonNull 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> Optional<T> get(@NonNull Object key, @NonNull Class<T> requiredType)
T
- The concrete typekey
- The cache keyrequiredType
- The required type@Nullable default 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