Class 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 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

      All Methods Instance Methods Concrete Methods 
      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> java.util.Optional<T> get​(java.lang.Object key, io.micronaut.core.type.Argument<T> requiredType)  
      <T> T get​(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.String getName()  
      com.github.benmanes.caffeine.cache.Cache getNativeCache()  
      void invalidate​(java.lang.Object key)  
      void invalidateAll()  
      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)  
      <T> java.util.Optional<T> putIfAbsent​(java.lang.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 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 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 Detail

      • 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 java.lang.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> java.util.Optional<T> get​(java.lang.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​(java.lang.Object key,
                         io.micronaut.core.type.Argument<T> requiredType,
                         java.util.function.Supplier<T> supplier)
        Specified by:
        get in interface io.micronaut.cache.SyncCache<com.github.benmanes.caffeine.cache.Cache>
      • invalidate

        public void invalidate​(java.lang.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
                        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:
        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> java.util.Optional<T> putIfAbsent​(java.lang.Object key,
                                                     T value)
        Specified by:
        putIfAbsent in interface io.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:
        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