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 async()
method to provide a
non-blocking implementation of this interface
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 should return an async API version of this cache interface implementation.
|
<T> Optional<T> |
get(Object key,
Argument<T> requiredType)
Resolve the given value for the given key.
|
<T> T |
get(Object key,
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.
|
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.
|
<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 Argument<T> requiredType)
T
- The concrete typekey
- The cache keyrequiredType
- The required type<T> T get(@Nonnull Object key, @Nonnull 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 cachedvoid 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@Nonnull default AsyncCache<C> async()
This method should return an async API version of this cache interface implementation.
The default behaviour assumes the cache implementation is running in-memory and performs no blocking
operations and hence simply delegates to the SyncCache
implementation.
If I/O operations are required implementors should override this API and provide an API that implements
AsyncCache
in a non-blocking manner.
AsyncCache
implementation for this cache