Class CacheManager


  • public final class CacheManager
    extends java.lang.Object
    A class used to create and manage cache instances on a per tenant basis
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CacheManager.Configuration
      A configuration class used by the cache manager to create managed cache instances with size and/or time-based eviction policies
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <K,​V>
      com.github.benmanes.caffeine.cache.Cache<K,​V>
      getCache​(java.lang.String cacheName)
      Get the managed cache with the given name for the current tenant.
      static <K,​V>
      com.github.benmanes.caffeine.cache.Cache<K,​V>
      getCache​(java.lang.String cacheName, CacheManager.Configuration configuration)
      Get or create the managed cache with the given name for the current tenant.
      static <K,​V>
      java.util.Map<K,​V>
      getCacheAsMap​(java.lang.String cacheName)
      Get the managed cache with the given name for the current tenant as a thread-safe map.
      static <K,​V>
      java.util.Map<K,​V>
      getCacheAsMap​(java.lang.String cacheName, CacheManager.Configuration configuration)
      Get or create the managed cache with the given name for the current tenant as a thread-safe map.
      java.util.Set<java.lang.String> getCacheNames()
      Get the cache names for the current tenant.
      static <K,​V>
      com.github.benmanes.caffeine.cache.stats.CacheStats
      getCacheStats​(java.lang.String cacheName)
      Get a snapshot of the cumulative statistics for the cache with the given name.
      static <K,​V>
      void
      invalidate​(java.lang.String cacheName, K key)
      Invalidate the entry with the provided key in the cache with the given name for the current tenant.
      static <K,​V>
      void
      invalidateAll​(java.lang.String cacheName)
      Invalidate all entries for the cache with the given name for the current tenant.
      static boolean isManaged​(java.lang.String cacheName)
      Indicates whether a cache with the given name is managed for the current tenant.
      static void removeCache​(java.lang.String cacheName)
      Remove the cache with the given name from the cache manager for the current tenant.
      static void reportCacheStats​(java.util.logging.Logger cacheClientLogger, java.lang.String cacheName)
      Reports the cache statistics in the caffeine cache.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getCacheNames

        public java.util.Set<java.lang.String> getCacheNames()
        Get the cache names for the current tenant.
        Returns:
        the cache names
      • getCache

        public static <K,​V> com.github.benmanes.caffeine.cache.Cache<K,​V> getCache​(java.lang.String cacheName)
        Get the managed cache with the given name for the current tenant.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        cacheName - the cache name
        Returns:
        the managed cache instance with the given name, or null if not exists
      • getCache

        public static <K,​V> com.github.benmanes.caffeine.cache.Cache<K,​V> getCache​(java.lang.String cacheName,
                                                                                               CacheManager.Configuration configuration)
        Get or create the managed cache with the given name for the current tenant.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        cacheName - the cache name
        configuration - the configuration
        Returns:
        a managed cache with the given name for the current tenant
      • getCacheAsMap

        public static <K,​V> java.util.Map<K,​V> getCacheAsMap​(java.lang.String cacheName)
        Get the managed cache with the given name for the current tenant as a thread-safe map.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        cacheName - the cache name
        Returns:
        the managed cache instance with the given name as a thread-safe map, or null if not exists
      • getCacheAsMap

        public static <K,​V> java.util.Map<K,​V> getCacheAsMap​(java.lang.String cacheName,
                                                                         CacheManager.Configuration configuration)
        Get or create the managed cache with the given name for the current tenant as a thread-safe map.
        Type Parameters:
        K - the key type
        V - the value type
        Parameters:
        cacheName - the cache name
        configuration - the configuration
        Returns:
        a managed cache with the given name for the current tenant as a thread-safe map
      • getCacheStats

        public static <K,​V> com.github.benmanes.caffeine.cache.stats.CacheStats getCacheStats​(java.lang.String cacheName)
        Get a snapshot of the cumulative statistics for the cache with the given name.
        Parameters:
        cacheName - the cache name
        Returns:
        a snapshot of the cumulative statistics for the cache with the given name, or null if not exists
      • invalidate

        public static <K,​V> void invalidate​(java.lang.String cacheName,
                                                  K key)
        Invalidate the entry with the provided key in the cache with the given name for the current tenant.
        Parameters:
        cacheName - the cache name
        key - the key
      • invalidateAll

        public static <K,​V> void invalidateAll​(java.lang.String cacheName)
        Invalidate all entries for the cache with the given name for the current tenant.
        Parameters:
        cacheName - the cache name
      • isManaged

        public static boolean isManaged​(java.lang.String cacheName)
        Indicates whether a cache with the given name is managed for the current tenant.
        Parameters:
        cacheName - the cache name
        Returns:
        true if a cache with the given name is managed for the current tenant, false otherwise
      • removeCache

        public static void removeCache​(java.lang.String cacheName)
        Remove the cache with the given name from the cache manager for the current tenant.
        Parameters:
        cacheName - the cache name
      • reportCacheStats

        public static void reportCacheStats​(java.util.logging.Logger cacheClientLogger,
                                            java.lang.String cacheName)
        Reports the cache statistics in the caffeine cache.
        Parameters:
        cacheClientLogger - used to report the statistics
        cacheName - the name of the cache to check