Package io.micronaut.cache
Class AbstractMapBasedSyncCache<C extends java.util.Map<java.lang.Object,java.lang.Object>>
- java.lang.Object
-
- io.micronaut.cache.AbstractMapBasedSyncCache<C>
-
- Type Parameters:
C- the native cache object, such thatC extends Map.
public abstract class AbstractMapBasedSyncCache<C extends java.util.Map<java.lang.Object,java.lang.Object>> extends java.lang.Object implements SyncCache<C>
AbstractSyncCacheimplementation that relies on a cache object that implements theMapinterface.- Since:
- 1.3.0
-
-
Constructor Summary
Constructors Constructor Description AbstractMapBasedSyncCache(io.micronaut.core.convert.ConversionService<?> conversionService, C nativeCache)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <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> Tget(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.io.micronaut.core.convert.ConversionService<?>getConversionService()abstract java.lang.StringgetName()CgetNativeCache()voidinvalidate(java.lang.Object key)Invalidate the value for the given key.voidinvalidateAll()Invalidate all cached values within this cache.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)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.-
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, getExecutorService
-
-
-
-
Constructor Detail
-
AbstractMapBasedSyncCache
public AbstractMapBasedSyncCache(io.micronaut.core.convert.ConversionService<?> conversionService, C nativeCache)- Parameters:
conversionService- the conversion servicenativeCache- the native cache
-
-
Method Detail
-
getConversionService
public io.micronaut.core.convert.ConversionService<?> getConversionService()
- Returns:
- The conversion service
-
get
@NonNull public <T> java.util.Optional<T> get(@NonNull java.lang.Object key, @NonNull io.micronaut.core.type.Argument<T> requiredType)Description copied from interface:SyncCacheResolve the given value for the given key.- Specified by:
getin interfaceSyncCache<C extends java.util.Map<java.lang.Object,java.lang.Object>>- Type Parameters:
T- The concrete type- Parameters:
key- The cache keyrequiredType- The required type- Returns:
- An optional containing the value if it exists and is able to be converted to the specified type
-
get
public <T> T get(@NonNull java.lang.Object key, @NonNull io.micronaut.core.type.Argument<T> requiredType, @NonNull java.util.function.Supplier<T> supplier)Description copied from interface:SyncCacheResolve the given value for the given key. If the value is not found the specifiedSupplierwill be invoked and the return value cached.- Specified by:
getin interfaceSyncCache<C extends java.util.Map<java.lang.Object,java.lang.Object>>- 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> java.util.Optional<T> putIfAbsent(@NonNull java.lang.Object key, @NonNull T value)Description copied from interface:SyncCacheCache the specified value using the specified key if it is not already present.
- Specified by:
putIfAbsentin interfaceSyncCache<C extends java.util.Map<java.lang.Object,java.lang.Object>>- 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
@NonNull public <T> T putIfAbsent(@NonNull java.lang.Object key, @NonNull java.util.function.Supplier<T> value)Description copied from interface:SyncCacheCache the supplied value using the specified key if it is not already present.
- Specified by:
putIfAbsentin interfaceSyncCache<C extends java.util.Map<java.lang.Object,java.lang.Object>>- 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
-
put
public void put(@NonNull java.lang.Object key, @NonNull java.lang.Object value)Description copied from interface:SyncCacheCache the specified value using the specified key.
-
invalidate
public void invalidate(@NonNull java.lang.Object key)Description copied from interface:SyncCacheInvalidate the value for the given key.- Specified by:
invalidatein interfaceSyncCache<C extends java.util.Map<java.lang.Object,java.lang.Object>>- Parameters:
key- The key to invalid
-
invalidateAll
public void invalidateAll()
Description copied from interface:SyncCacheInvalidate all cached values within this cache.- Specified by:
invalidateAllin interfaceSyncCache<C extends java.util.Map<java.lang.Object,java.lang.Object>>
-
getName
public abstract java.lang.String getName()
-
getNativeCache
public C getNativeCache()
- Specified by:
getNativeCachein interfaceCache<C extends java.util.Map<java.lang.Object,java.lang.Object>>- Returns:
- The native cache implementation
-
-