Package io.micronaut.cache.caffeine
Class DefaultSyncCache
- java.lang.Object
-
- io.micronaut.cache.caffeine.DefaultSyncCache
-
- All Implemented Interfaces:
io.micronaut.cache.Cache<com.github.benmanes.caffeine.cache.Cache>,io.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
@EachBean(io.micronaut.cache.CacheConfiguration.class) public class DefaultSyncCache extends java.lang.Object implements io.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>A default
SyncCacheimplementation based on CaffeineSince 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
-
-
Constructor Summary
Constructors Constructor Description DefaultSyncCache(io.micronaut.cache.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.github.benmanes.caffeine.cache.CachebuildCache(io.micronaut.cache.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)<T> Tget(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType, java.util.function.Supplier<T> supplier)org.reactivestreams.Publisher<io.micronaut.cache.CacheInfo>getCacheInfo()java.lang.StringgetName()com.github.benmanes.caffeine.cache.CachegetNativeCache()voidinvalidate(java.lang.Object key)voidinvalidateAll()voidput(java.lang.Object key, java.lang.Object value)Cache the specified value using the specified key.<T> TputIfAbsent(java.lang.Object key, java.util.function.Supplier<T> value)<T> java.util.Optional<T>putIfAbsent(java.lang.Object key, T value)
-
-
-
Constructor Detail
-
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(io.micronaut.cache.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 Detail
-
getCacheInfo
public org.reactivestreams.Publisher<io.micronaut.cache.CacheInfo> getCacheInfo()
- Specified by:
getCacheInfoin interfaceio.micronaut.cache.Cache<com.github.benmanes.caffeine.cache.Cache>
-
getName
public java.lang.String getName()
- Specified by:
getNamein interfaceio.micronaut.cache.Cache<com.github.benmanes.caffeine.cache.Cache>
-
getNativeCache
public com.github.benmanes.caffeine.cache.Cache getNativeCache()
- Specified by:
getNativeCachein interfaceio.micronaut.cache.Cache<com.github.benmanes.caffeine.cache.Cache>
-
get
public <T> java.util.Optional<T> get(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType)- Specified by:
getin interfaceio.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
-
get
public <T> T get(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType, java.util.function.Supplier<T> supplier)- Specified by:
getin interfaceio.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
-
invalidate
public void invalidate(java.lang.Object key)
- Specified by:
invalidatein interfaceio.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
-
invalidateAll
public void invalidateAll()
- Specified by:
invalidateAllin interfaceio.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
-
put
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- Specified by:
putin interfaceio.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>- Parameters:
key- the key with which the specified value is to be associatedvalue- the value to be associated with the specified key
-
putIfAbsent
public <T> java.util.Optional<T> putIfAbsent(java.lang.Object key, T value)- Specified by:
putIfAbsentin interfaceio.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
-
putIfAbsent
public <T> T putIfAbsent(java.lang.Object key, java.util.function.Supplier<T> value)- Specified by:
putIfAbsentin interfaceio.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
-
buildCache
protected com.github.benmanes.caffeine.cache.Cache buildCache(io.micronaut.cache.CacheConfiguration cacheConfiguration)
Build a cache from the given configurations.- Parameters:
cacheConfiguration- The cache configurations- Returns:
- cache
-
-