Class CacheManager

java.lang.Object
com.peterphi.std.guice.common.cached.CacheManager

public final class CacheManager extends Object
Holds weak references to a number of caches, allowing a UI to list all cached data or to invalidate all cached data
  • Method Summary

    Modifier and Type
    Method
    Description
    static <K, V, K1 extends K, V1 extends V>
    com.google.common.cache.Cache<K1,V1>
    build(String name, com.google.common.cache.CacheBuilder<K,V> builder)
    Build and register a new cache; the cache will be referenced weakly, and the name provided referenced strongly
    static void
    Used to remove all caches from the manager; this should not normally be needed
    static Map<com.google.common.cache.Cache,String>
     
    static Map<String,List<com.google.common.cache.Cache>>
    Retrieve caches grouped by their name; there can be a lot of caches with the same name (e.g.
    static void
     
    static <T> SingleItemCache<T>
    register(String name, SingleItemCache<T> cache)
    Register a SingleItemCache; this is strictly unnecessary because a
    static <K, V, T extends com.google.common.cache.Cache<K, V>>
    T
    register(String name, T cache)
    Register a new cache; the cache will be referenced weakly, and the name provided referenced strongly

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • build

      public static <K, V, K1 extends K, V1 extends V> com.google.common.cache.Cache<K1,V1> build(String name, com.google.common.cache.CacheBuilder<K,V> builder)
      Build and register a new cache; the cache will be referenced weakly, and the name provided referenced strongly
      Type Parameters:
      K - cache key type
      V - cache value type
      Parameters:
      name - non-unique descriptive name of the cache
      builder - a builder upon which .build() should be invoked
      Returns:
    • register

      public static <K, V, T extends com.google.common.cache.Cache<K, V>> T register(String name, T cache)
      Register a new cache; the cache will be referenced weakly, and the name provided referenced strongly
      Type Parameters:
      K - cache key type
      V - cache value type
      Parameters:
      name - non-unique descriptive name of the cache
      cache - the cache object to register
      Returns:
    • register

      public static <T> SingleItemCache<T> register(String name, SingleItemCache<T> cache)
      Register a SingleItemCache; this is strictly unnecessary because a
      Type Parameters:
      T -
      Parameters:
      name -
      cache -
      Returns:
    • invalidateAll

      public static void invalidateAll()
    • forgetAllCaches

      public static void forgetAllCaches()
      Used to remove all caches from the manager; this should not normally be needed
    • getCachesByName

      public static Map<String,List<com.google.common.cache.Cache>> getCachesByName()
      Retrieve caches grouped by their name; there can be a lot of caches with the same name (e.g. SessionScoped caches)
      Returns:
    • getCaches

      public static Map<com.google.common.cache.Cache,String> getCaches()
      Returns:
      Throws:
      RuntimeException - if we got too many ConcurrentModificationException errors trying to take a copy of the map of caches