Class JCacheSyncCache

  • All Implemented Interfaces:
    Cache<javax.cache.Cache>, SyncCache<javax.cache.Cache>

    @Internal
    public class JCacheSyncCache
    extends java.lang.Object
    implements SyncCache<javax.cache.Cache>
    An implementation of SyncCache for JCache.
    Since:
    1.1.0
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected JCacheSyncCache​(javax.cache.Cache<?,​?> nativeCache, io.micronaut.core.convert.ConversionService<?> conversionService, java.util.concurrent.ExecutorService ioExecutor)
      Default constructor.
    • Method Summary

      All Methods Instance 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> T get​(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.
      java.util.concurrent.ExecutorService getExecutorService()  
      java.lang.String getName()  
      javax.cache.Cache<?,​?> getNativeCache()  
      void invalidate​(java.lang.Object key)
      Invalidate the value for the given key.
      void invalidateAll()
      Invalidate all cached values within this cache.
      void put​(java.lang.Object key, java.lang.Object value)
      Cache the specified value using the specified key.
      <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
    • Constructor Detail

      • JCacheSyncCache

        protected JCacheSyncCache​(@NonNull
                                  javax.cache.Cache<?,​?> nativeCache,
                                  io.micronaut.core.convert.ConversionService<?> conversionService,
                                  java.util.concurrent.ExecutorService ioExecutor)
        Default constructor.
        Parameters:
        nativeCache - The native cache
        conversionService - The conversion service
        ioExecutor - The IO executor
    • Method Detail

      • getExecutorService

        public java.util.concurrent.ExecutorService getExecutorService()
        Specified by:
        getExecutorService in interface SyncCache<javax.cache.Cache>
        Returns:
        The executor service used to construct the default asynchronous cache.
      • get

        public <T> java.util.Optional<T> get​(java.lang.Object key,
                                             io.micronaut.core.type.Argument<T> requiredType)
        Description copied from interface: SyncCache
        Resolve the given value for the given key.
        Specified by:
        get in interface SyncCache<javax.cache.Cache>
        Type Parameters:
        T - The concrete type
        Parameters:
        key - The cache key
        requiredType - 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: SyncCache
        Resolve the given value for the given key. If the value is not found the specified Supplier will be invoked and the return value cached.
        Specified by:
        get in interface SyncCache<javax.cache.Cache>
        Type Parameters:
        T - The concrete type
        Parameters:
        key - The cache key
        requiredType - The required type
        supplier - 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: SyncCache

        Cache the specified value using the specified key if it is not already present.

        Specified by:
        putIfAbsent in interface SyncCache<javax.cache.Cache>
        Type Parameters:
        T - The concrete type
        Parameters:
        key - the key with which the specified value is to be associated
        value - 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

        public void put​(java.lang.Object key,
                        java.lang.Object value)
        Description copied from interface: SyncCache

        Cache the specified value using the specified key.

        Specified by:
        put in interface SyncCache<javax.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
      • invalidate

        public void invalidate​(java.lang.Object key)
        Description copied from interface: SyncCache
        Invalidate the value for the given key.
        Specified by:
        invalidate in interface SyncCache<javax.cache.Cache>
        Parameters:
        key - The key to invalid
      • invalidateAll

        public void invalidateAll()
        Description copied from interface: SyncCache
        Invalidate all cached values within this cache.
        Specified by:
        invalidateAll in interface SyncCache<javax.cache.Cache>
      • getName

        public java.lang.String getName()
        Specified by:
        getName in interface Cache<javax.cache.Cache>
        Returns:
        The name of the cache
      • getNativeCache

        public javax.cache.Cache<?,​?> getNativeCache()
        Specified by:
        getNativeCache in interface Cache<javax.cache.Cache>
        Returns:
        The native cache implementation