Package ubic.gemma.persistence.util
Class CacheUtils
- java.lang.Object
-
- ubic.gemma.persistence.util.CacheUtils
-
public class CacheUtils extends Object
Created by tesarst on 04/04/17. Provides common methods for cache manipulation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CacheUtils.Lock
-
Constructor Summary
Constructors Constructor Description CacheUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CacheUtils.Lock
acquireReadLock(Cache cache, Object key)
static CacheUtils.Lock
acquireWriteLock(Cache cache, Object key)
Acquire an exclusive write lock on the given key in the cache.static boolean
containsKey(Cache cache, Object key)
Check if a cache contains a given key.static void
evictIf(Cache cache, Predicate<Object> predicate)
Evict entries from the cache where the key is matching a given predicate.static Cache
getCache(CacheManager cacheManager, String cacheName)
Obtain a cache by its name, raising an exception if unavailable.static Collection<?>
getKeys(Cache cache)
Obtain the keys of all elements of a cache.static int
getSize(Cache cache)
-
-
-
Method Detail
-
getCache
public static Cache getCache(CacheManager cacheManager, String cacheName) throws RuntimeException
Obtain a cache by its name, raising an exception if unavailable.- Throws:
RuntimeException
- if the cache identified by name is missing
-
getSize
public static int getSize(Cache cache)
-
containsKey
public static boolean containsKey(Cache cache, Object key)
Check if a cache contains a given key.
-
getKeys
public static Collection<?> getKeys(Cache cache)
Obtain the keys of all elements of a cache.
-
evictIf
public static void evictIf(Cache cache, Predicate<Object> predicate)
Evict entries from the cache where the key is matching a given predicate.If keys cannot be enumerated by the cache provider, all entries are cleared.
-
acquireReadLock
public static CacheUtils.Lock acquireReadLock(Cache cache, Object key)
-
acquireWriteLock
public static CacheUtils.Lock acquireWriteLock(Cache cache, Object key)
Acquire an exclusive write lock on the given key in the cache.This can be used for preventing other threads from performing the same expensive operations.
-
-