Package io.micronaut.cache.jcache
Class JCacheSyncCache
java.lang.Object
io.micronaut.cache.jcache.JCacheSyncCache
An implementation of
SyncCache
for JCache.- Since:
- 1.1.0
- Author:
- graemerocher
-
Constructor Summary
ModifierConstructorDescriptionprotected
JCacheSyncCache
(@NonNull javax.cache.Cache<?, ?> nativeCache, io.micronaut.core.convert.ConversionService conversionService, ExecutorService ioExecutor) Default constructor. -
Method Summary
Modifier and TypeMethodDescription<T> T
get
(@NonNull Object key, @NonNull io.micronaut.core.type.Argument<T> requiredType, @NonNull Supplier<T> supplier) Resolve the given value for the given key.<T> Optional<T>
Resolve the given value for the given key.getName()
javax.cache.Cache<?,
?> void
invalidate
(Object key) Invalidate the value for the given key.void
Invalidate all cached values within this cache.void
Cache the specified value using the specified key.<T> @NonNull Optional<T>
putIfAbsent
(@NonNull 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.Cache
getCacheInfo
Methods inherited from interface io.micronaut.cache.SyncCache
async, get, get, putIfAbsent
-
Constructor Details
-
JCacheSyncCache
protected JCacheSyncCache(@NonNull @NonNull javax.cache.Cache<?, ?> nativeCache, io.micronaut.core.convert.ConversionService conversionService, ExecutorService ioExecutor) Default constructor.- Parameters:
nativeCache
- The native cacheconversionService
- The conversion serviceioExecutor
- The IO executor
-
-
Method Details
-
getExecutorService
- Specified by:
getExecutorService
in interfaceSyncCache<javax.cache.Cache>
- Returns:
- The executor service used to construct the default asynchronous cache.
-
get
Description copied from interface:SyncCache
Resolve the given value for the given key. -
get
public <T> T get(@NonNull @NonNull Object key, @NonNull @NonNull io.micronaut.core.type.Argument<T> requiredType, @NonNull @NonNull Supplier<T> supplier) Description copied from interface:SyncCache
Resolve the given value for the given key. If the value is not found the specifiedSupplier
will be invoked and the return value cached.- Specified by:
get
in interfaceSyncCache<javax.cache.Cache>
- 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
@NonNull public <T> @NonNull Optional<T> putIfAbsent(@NonNull @NonNull Object key, @NonNull T value) Description copied from interface:SyncCache
Cache the specified value using the specified key if it is not already present.
- Specified by:
putIfAbsent
in interfaceSyncCache<javax.cache.Cache>
- 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
-
put
Description copied from interface:SyncCache
Cache the specified value using the specified key.
-
invalidate
Description copied from interface:SyncCache
Invalidate the value for the given key.- Specified by:
invalidate
in interfaceSyncCache<javax.cache.Cache>
- Parameters:
key
- The key to invalid
-
invalidateAll
public void invalidateAll()Description copied from interface:SyncCache
Invalidate all cached values within this cache.- Specified by:
invalidateAll
in interfaceSyncCache<javax.cache.Cache>
-
getName
-
getNativeCache
public javax.cache.Cache<?,?> getNativeCache()- Specified by:
getNativeCache
in interfaceCache<javax.cache.Cache>
- Returns:
- The native cache implementation
-