@EachBean(value=CacheConfiguration.class) public class DefaultSyncCache extends java.lang.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> java.util.Optional<T> |
get(java.lang.Object key,
io.micronaut.core.type.Argument<T> requiredType)
Resolve the given value for the given key.
|
<T> T |
get(java.lang.Object key,
io.micronaut.core.type.Argument<T> requiredType,
java.util.function.Supplier<T> supplier)
Resolve the given value for the given key.
|
org.reactivestreams.Publisher<CacheInfo> |
getCacheInfo() |
java.lang.String |
getName() |
com.github.benmanes.caffeine.cache.Cache |
getNativeCache() |
void |
invalidate(java.lang.Object key)
Invalidate the value for the given key.
|
void |
invalidateAll()
Invalidate all cached values within this cache.
|
void |
put(java.lang.Object key,
java.lang.Object value)
Cache the specified value using the specified key.
|
<T> T |
putIfAbsent(java.lang.Object key,
java.util.function.Supplier<T> value)
Cache the supplied value using the specified key if it is not already present.
|
<T> java.util.Optional<T> |
putIfAbsent(java.lang.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 java.lang.String getName()
public com.github.benmanes.caffeine.cache.Cache getNativeCache()
getNativeCache
in interface Cache<com.github.benmanes.caffeine.cache.Cache>
public <T> java.util.Optional<T> get(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType)
SyncCache
public <T> T get(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType, java.util.function.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(java.lang.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 java.lang.Object key, @Nullable java.lang.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> java.util.Optional<T> putIfAbsent(java.lang.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(java.lang.Object key, java.util.function.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