@EachBean(value=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.
Constructor and Description |
---|
DefaultSyncCache(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.
|
Modifier and Type | Method and Description |
---|---|
protected com.github.benmanes.caffeine.cache.Cache |
buildCache(CacheConfiguration cacheConfiguration)
Build a cache from the given configurations.
|
<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.
|
org.reactivestreams.Publisher<CacheInfo> |
getCacheInfo() |
String |
getName() |
com.github.benmanes.caffeine.cache.Cache |
getNativeCache() |
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> 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
async, get, get, getExecutorService
public DefaultSyncCache(DefaultCacheConfiguration cacheConfiguration, io.micronaut.context.ApplicationContext applicationContext, io.micronaut.core.convert.ConversionService<?> conversionService)
cacheConfiguration
- The cache configurationsapplicationContext
- The application contextconversionService
- To convert the value from the cache into given required type@Inject public DefaultSyncCache(CacheConfiguration cacheConfiguration, io.micronaut.context.ApplicationContext applicationContext, io.micronaut.core.convert.ConversionService<?> conversionService)
cacheConfiguration
- The cache configurationsapplicationContext
- The application contextconversionService
- To convert the value from the cache into given required typepublic org.reactivestreams.Publisher<CacheInfo> getCacheInfo()
getCacheInfo
in interface Cache<com.github.benmanes.caffeine.cache.Cache>
public String getName()
public com.github.benmanes.caffeine.cache.Cache getNativeCache()
getNativeCache
in interface Cache<com.github.benmanes.caffeine.cache.Cache>
public <T> Optional<T> get(Object key, io.micronaut.core.type.Argument<T> requiredType)
SyncCache
public <T> T get(Object key, io.micronaut.core.type.Argument<T> requiredType, Supplier<T> supplier)
SyncCache
Supplier
will
be invoked and the return value cached.get
in interface SyncCache<com.github.benmanes.caffeine.cache.Cache>
T
- The concrete typekey
- The cache keyrequiredType
- The required typesupplier
- The supplier that should be invoked if the value is not foundpublic void invalidate(Object key)
SyncCache
invalidate
in interface SyncCache<com.github.benmanes.caffeine.cache.Cache>
key
- The key to invalidpublic void invalidateAll()
SyncCache
invalidateAll
in interface SyncCache<com.github.benmanes.caffeine.cache.Cache>
public void put(@NonNull Object key, @Nullable Object value)
Cache the specified value using the specified key. If the value is null, it will call
invalidate(Object)
passing the key
public <T> Optional<T> putIfAbsent(Object key, T value)
SyncCache
Cache the specified value using the specified key if it is not already present.
putIfAbsent
in interface SyncCache<com.github.benmanes.caffeine.cache.Cache>
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 cachedpublic <T> T putIfAbsent(Object key, Supplier<T> value)
SyncCache
Cache the supplied value using the specified key if it is not already present.
putIfAbsent
in interface SyncCache<com.github.benmanes.caffeine.cache.Cache>
T
- The concrete typekey
- the key with which the specified value is to be associatedvalue
- the value supplier to be associated with the specified keyprotected com.github.benmanes.caffeine.cache.Cache buildCache(CacheConfiguration cacheConfiguration)
cacheConfiguration
- The cache configurations