Class CacheManager
java.lang.Object
com.peterphi.std.guice.common.cached.CacheManager
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 TypeMethodDescriptionstatic <K,V, K1 extends K, V1 extends V>
com.google.common.cache.Cache<K1,V1> Build and register a new cache; the cache will be referenced weakly, and the name provided referenced stronglystatic voidUsed to remove all caches from the manager; this should not normally be neededRetrieve caches grouped by their name; there can be a lot of caches with the same name (e.g.static voidstatic <T> SingleItemCache<T>register(String name, SingleItemCache<T> cache) Register a SingleItemCache; this is strictly unnecessary because astatic <K,V, T extends com.google.common.cache.Cache<K, V>>
TRegister a new cache; the cache will be referenced weakly, and the name provided referenced strongly
-
Method Details
-
build
public static <K,V, com.google.common.cache.Cache<K1,K1 extends K, V1 extends V> 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 typeV- cache value type- Parameters:
name- non-unique descriptive name of the cachebuilder- a builder upon which .build() should be invoked- Returns:
-
register
public static <K,V, T registerT extends com.google.common.cache.Cache<K, V>> (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 typeV- cache value type- Parameters:
name- non-unique descriptive name of the cachecache- the cache object to register- Returns:
-
register
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
Retrieve caches grouped by their name; there can be a lot of caches with the same name (e.g.SessionScopedcaches)- Returns:
-
getCaches
- Returns:
- Throws:
RuntimeException- if we got too many ConcurrentModificationException errors trying to take a copy of the map of caches
-