Package ubic.gemma.persistence.cache
Class CacheUtils
java.lang.Object
ubic.gemma.persistence.cache.CacheUtils
Created by tesarst on 04/04/17.
Provides common methods for cache manipulation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic CacheKeyLock.LockAcquisition
acquireReadLock
(org.springframework.cache.Cache cache, Object key) Acquire a read-only lock on the given key in the cache.static CacheKeyLock.LockAcquisition
acquireWriteLock
(org.springframework.cache.Cache cache, Object key) Acquire an exclusive write lock on the given key in the cache.static boolean
containsKey
(org.springframework.cache.Cache cache, Object key) Check if a cache contains a given key.static void
Evict entries from the cache where the key is matching a given predicate.static org.springframework.cache.Cache
Obtain a cache by its name, raising an exception if unavailable.static Collection
<?> getKeys
(org.springframework.cache.Cache cache) Obtain the keys of all elements of a cache.static int
getSize
(org.springframework.cache.Cache cache)
-
Constructor Details
-
CacheUtils
public CacheUtils()
-
-
Method Details
-
getCache
public static org.springframework.cache.Cache getCache(org.springframework.cache.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(org.springframework.cache.Cache cache) -
containsKey
Check if a cache contains a given key. -
getKeys
Obtain the keys of all elements of a cache. -
evictIf
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 CacheKeyLock.LockAcquisition acquireReadLock(org.springframework.cache.Cache cache, Object key) throws InterruptedException Acquire a read-only lock on the given key in the cache.- Returns:
- an acquired read lock on the given cache key
- Throws:
InterruptedException
- if the current thread is interrupted while waiting for the lock
-
acquireWriteLock
public static CacheKeyLock.LockAcquisition acquireWriteLock(org.springframework.cache.Cache cache, Object key) throws InterruptedException Acquire an exclusive write lock on the given key in the cache.- Returns:
- an acquired write lock on the given cache key
- Throws:
InterruptedException
- if the current thread is interrupted while waiting for the lock
-