Package io.micronaut.cache.ehcache
Class EhcacheSyncCache
java.lang.Object
io.micronaut.cache.ehcache.EhcacheSyncCache
A
SyncCache implementation based on Ehcache.- Since:
- 1.0.0
- Author:
- Álvaro Sánchez-Mariscal
-
Constructor Summary
ConstructorsConstructorDescriptionEhcacheSyncCache(io.micronaut.core.convert.ConversionService conversionService, EhcacheConfiguration configuration, org.ehcache.Cache nativeCache, ExecutorService executorService, org.ehcache.core.spi.service.StatisticsService statisticsService) -
Method Summary
Modifier and TypeMethodDescription<T> @NonNull Optional<T>Resolve the given value for the given key.<T> Tget(@NonNull Object key, @NonNull io.micronaut.core.type.Argument<T> requiredType, @NonNull Supplier<T> supplier) Resolve the given value for the given key.org.reactivestreams.Publisher<CacheInfo>getName()org.ehcache.Cachevoidinvalidate(@NonNull Object key) Invalidate the value for the given key.voidInvalidate all cached values within this cache.voidCache the specified value using the specified key.<T> @NonNull Optional<T>putIfAbsent(@NonNull 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, waitMethods inherited from interface io.micronaut.cache.SyncCache
async, get, get, putIfAbsent
-
Constructor Details
-
EhcacheSyncCache
public EhcacheSyncCache(io.micronaut.core.convert.ConversionService conversionService, EhcacheConfiguration configuration, org.ehcache.Cache nativeCache, @Named("io") ExecutorService executorService, org.ehcache.core.spi.service.StatisticsService statisticsService) - Parameters:
conversionService- the conversion serviceconfiguration- the configurationnativeCache- the native cacheexecutorService- the executor service to offload synchronous operationsstatisticsService- th Ehcache statistics service
-
-
Method Details
-
getExecutorService
- Specified by:
getExecutorServicein interfaceSyncCache<org.ehcache.Cache>- Returns:
- The executor service used to construct the default asynchronous cache.
-
get
@NonNull public <T> @NonNull Optional<T> get(@NonNull @NonNull Object key, @NonNull @NonNull io.micronaut.core.type.Argument<T> requiredType) Description copied from interface:SyncCacheResolve the given value for the given key. -
get
public <T> T get(@NonNull @NonNull Object key, @NonNull @NonNull io.micronaut.core.type.Argument<T> requiredType, @NonNull @NonNull 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<org.ehcache.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
-
putIfAbsent
@NonNull public <T> @NonNull Optional<T> putIfAbsent(@NonNull @NonNull 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<org.ehcache.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
-
put
Description copied from interface:SyncCacheCache the specified value using the specified key.
-
invalidate
Description copied from interface:SyncCacheInvalidate the value for the given key.- Specified by:
invalidatein interfaceSyncCache<org.ehcache.Cache>- 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<org.ehcache.Cache>
-
getName
-
getNativeCache
public org.ehcache.Cache getNativeCache()- Specified by:
getNativeCachein interfaceCache<org.ehcache.Cache>- Returns:
- The native cache implementation
-
getCacheInfo
- Specified by:
getCacheInfoin interfaceCache<org.ehcache.Cache>- Returns:
- The cache information.
-