Package io.micronaut.cache.caffeine
Class DefaultSyncCache
java.lang.Object
io.micronaut.cache.caffeine.DefaultSyncCache
- All Implemented Interfaces:
Cache<com.github.benmanes.caffeine.cache.Cache>
,SyncCache<com.github.benmanes.caffeine.cache.Cache>
@EachBean(CacheConfiguration.class)
public class DefaultSyncCache
extends Object
implements SyncCache<com.github.benmanes.caffeine.cache.Cache>
A default SyncCache
implementation based on Caffeine
Since Caffeine is a non-blocking in-memory cache the SyncCache.async()
method will return an implementation that
runs operations in the current thread.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Constructor Summary
ConstructorDescriptionDefaultSyncCache
(CacheConfiguration cacheConfiguration, io.micronaut.context.ApplicationContext applicationContext, io.micronaut.core.convert.ConversionService conversionService) Construct a sync cache implementation with given configurations.DefaultSyncCache
(DefaultCacheConfiguration cacheConfiguration, io.micronaut.context.ApplicationContext applicationContext, io.micronaut.core.convert.ConversionService conversionService) Construct a sync cache implementation with given configurations. -
Method Summary
Modifier and TypeMethodDescriptionprotected com.github.benmanes.caffeine.cache.Cache
buildCache
(CacheConfiguration cacheConfiguration) Build a cache from the given configurations.<T> Optional<T>
Resolve the given value for the given key.<T> T
Resolve the given value for the given key.org.reactivestreams.Publisher<CacheInfo>
getName()
com.github.benmanes.caffeine.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> 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.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.SyncCache
async, get, get, getExecutorService
-
Constructor Details
-
DefaultSyncCache
public DefaultSyncCache(DefaultCacheConfiguration cacheConfiguration, io.micronaut.context.ApplicationContext applicationContext, io.micronaut.core.convert.ConversionService conversionService) Construct a sync cache implementation with given configurations.- Parameters:
cacheConfiguration
- The cache configurationsapplicationContext
- The application contextconversionService
- To convert the value from the cache into given required type
-
DefaultSyncCache
@Inject public DefaultSyncCache(CacheConfiguration cacheConfiguration, io.micronaut.context.ApplicationContext applicationContext, io.micronaut.core.convert.ConversionService conversionService) Construct a sync cache implementation with given configurations.- Parameters:
cacheConfiguration
- The cache configurationsapplicationContext
- The application contextconversionService
- To convert the value from the cache into given required type
-
-
Method Details
-
getCacheInfo
- Specified by:
getCacheInfo
in interfaceCache<com.github.benmanes.caffeine.cache.Cache>
- Returns:
- The cache information.
-
getName
-
getNativeCache
public com.github.benmanes.caffeine.cache.Cache getNativeCache()- Specified by:
getNativeCache
in interfaceCache<com.github.benmanes.caffeine.cache.Cache>
- Returns:
- The native cache implementation
-
get
Description copied from interface:SyncCache
Resolve the given value for the given key. -
get
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<com.github.benmanes.caffeine.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
-
invalidate
Description copied from interface:SyncCache
Invalidate the value for the given key.- Specified by:
invalidate
in interfaceSyncCache<com.github.benmanes.caffeine.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<com.github.benmanes.caffeine.cache.Cache>
-
put
Cache the specified value using the specified key. If the value is null, it will call
invalidate(Object)
passing the key -
putIfAbsent
Description copied from interface:SyncCache
Cache the specified value using the specified key if it is not already present.
- Specified by:
putIfAbsent
in interfaceSyncCache<com.github.benmanes.caffeine.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
-
putIfAbsent
Description copied from interface:SyncCache
Cache the supplied value using the specified key if it is not already present.
- Specified by:
putIfAbsent
in interfaceSyncCache<com.github.benmanes.caffeine.cache.Cache>
- Type Parameters:
T
- The concrete type- Parameters:
key
- the key with which the specified value is to be associatedvalue
- the value supplier to be associated with the specified key- Returns:
- An optional of the existing value or the new value returned by the supplier
-
buildCache
protected com.github.benmanes.caffeine.cache.Cache buildCache(CacheConfiguration cacheConfiguration) Build a cache from the given configurations.- Parameters:
cacheConfiguration
- The cache configurations- Returns:
- cache
-