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 Object implements io.micronaut.cache.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.

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

    Modifier and Type
    Method
    Description
    protected com.github.benmanes.caffeine.cache.Cache
    buildCache(io.micronaut.cache.CacheConfiguration cacheConfiguration)
    Build a cache from the given configurations.
    <T> Optional<T>
    get(Object key, io.micronaut.core.type.Argument<T> requiredType)
     
    <T> T
    get(Object key, io.micronaut.core.type.Argument<T> requiredType, Supplier<T> supplier)
     
    org.reactivestreams.Publisher<io.micronaut.cache.CacheInfo>
     
     
    com.github.benmanes.caffeine.cache.Cache
     
    void
     
    void
     
    void
    put(@NonNull Object key, @Nullable Object value)
    Cache the specified value using the specified key.
    <T> T
    putIfAbsent(Object key, Supplier<T> value)
     
    <T> Optional<T>
    putIfAbsent(Object key, T value)
     

    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.SyncCache

    async, get, get, getExecutorService
  • Constructor Details

    • 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 configurations
      applicationContext - The application context
      conversionService - 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 configurations
      applicationContext - The application context
      conversionService - To convert the value from the cache into given required type
  • Method Details

    • getCacheInfo

      public org.reactivestreams.Publisher<io.micronaut.cache.CacheInfo> getCacheInfo()
      Specified by:
      getCacheInfo in interface io.micronaut.cache.Cache<com.github.benmanes.caffeine.cache.Cache>
    • getName

      public String getName()
      Specified by:
      getName in interface io.micronaut.cache.Cache<com.github.benmanes.caffeine.cache.Cache>
    • getNativeCache

      public com.github.benmanes.caffeine.cache.Cache getNativeCache()
      Specified by:
      getNativeCache in interface io.micronaut.cache.Cache<com.github.benmanes.caffeine.cache.Cache>
    • get

      public <T> Optional<T> get(Object key, io.micronaut.core.type.Argument<T> requiredType)
      Specified by:
      get in interface io.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
    • get

      public <T> T get(Object key, io.micronaut.core.type.Argument<T> requiredType, Supplier<T> supplier)
      Specified by:
      get in interface io.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
    • invalidate

      public void invalidate(Object key)
      Specified by:
      invalidate in interface io.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
    • invalidateAll

      public void invalidateAll()
      Specified by:
      invalidateAll in interface io.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
    • put

      public void put(@NonNull @NonNull Object key, @Nullable @Nullable 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:
      put in interface io.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
      Parameters:
      key - the key with which the specified value is to be associated
      value - the value to be associated with the specified key
    • putIfAbsent

      public <T> Optional<T> putIfAbsent(Object key, T value)
      Specified by:
      putIfAbsent in interface io.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
    • putIfAbsent

      public <T> T putIfAbsent(Object key, Supplier<T> value)
      Specified by:
      putIfAbsent in interface io.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