Class CacheManager


  • public final class CacheManager
    extends 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 Detail

      • getCacheNames

        public Set<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​(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​(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> Map<K,​V> getCacheAsMap​(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> Map<K,​V> getCacheAsMap​(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 com.github.benmanes.caffeine.cache.stats.CacheStats getCacheStats​(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 void invalidate​(String cacheName,
                                      Object 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 void invalidateAll​(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​(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​(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​(Logger cacheClientLogger,
                                            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