Package uk.gov.gchq.gaffer.cache
Interface ICacheService
-
- All Known Implementing Classes:
HashMapCacheService,HazelcastCacheService,JcsCacheService
public interface ICacheServiceThe cache service interface which enables the cache service loader to instantiate any service no matter the implementation. All services should be able to provide a cache and methods to interact with it.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidclearCache(String cacheName)Clear the contents of the specified cache.default <K,V>
Iterable<K>getAllKeysFromCache(String cacheName)Get all of the keys associated with the specified cache.default <K,V>
Iterable<V>getAllValuesFromCache(String cacheName)Get all of the values associated with the specified cache.<K,V>
ICache<K,V>getCache(String cacheName)Get the named cache from the cache service.default <K,V>
VgetFromCache(String cacheName, K key)Get the value associated with the specified cache and key.voidinitialise(Properties properties)Initialise the cache service based on the suppliedPropertiesobject.default <K,V>
voidputInCache(String cacheName, K key, V value)Add a new key-value pair to the specified cache.default <K,V>
voidputSafeInCache(String cacheName, K key, V value)Add a new key-value pair to the specified cache, but only if there is no existing entry associated with the specified key.default <K> voidremoveFromCache(String cacheName, K key)Remove the entry associated with the specified key from the specified cache.voidshutdown()Shutdown the cache service.default intsizeOfCache(String cacheName)Retrieve the size of the specified cache.
-
-
-
Method Detail
-
initialise
void initialise(Properties properties)
Initialise the cache service based on the suppliedPropertiesobject.- Parameters:
properties- the Properties object to apply to the cache service
-
shutdown
void shutdown()
Shutdown the cache service.
-
getCache
<K,V> ICache<K,V> getCache(String cacheName)
Get the named cache from the cache service.- Type Parameters:
K- The object type that acts as the key for the cacheV- The value that is stored in the cache- Parameters:
cacheName- the name of the cache to retrieve- Returns:
- the requested cache object
-
getFromCache
default <K,V> V getFromCache(String cacheName, K key) throws CacheOperationException
Get the value associated with the specified cache and key.- Type Parameters:
K- The object type that acts as the key for the cacheV- The value that is stored in the cache- Parameters:
cacheName- the name of the cache to look inkey- the key of the entry to lookup- Returns:
- the requested cache object
- Throws:
CacheOperationException- if issue getting from cache.
-
putInCache
default <K,V> void putInCache(String cacheName, K key, V value) throws CacheOperationException
Add a new key-value pair to the specified cache.- Type Parameters:
K- The object type that acts as the key for the cacheV- The value that is stored in the cache- Parameters:
cacheName- the name of the cachekey- the key to addvalue- the value to add- Throws:
CacheOperationException- if issue adding to cache.
-
putSafeInCache
default <K,V> void putSafeInCache(String cacheName, K key, V value) throws CacheOperationException
Add a new key-value pair to the specified cache, but only if there is no existing entry associated with the specified key.- Type Parameters:
K- The object type that acts as the key for the cacheV- The value that is stored in the cache- Parameters:
cacheName- the name of the cachekey- the key to addvalue- the value to add- Throws:
CacheOperationException- if issue adding to cache.
-
removeFromCache
default <K> void removeFromCache(String cacheName, K key)
Remove the entry associated with the specified key from the specified cache.- Type Parameters:
K- The object type that acts as the key for the cache- Parameters:
cacheName- the name of the cache to look inkey- the key of the entry to remove
-
getAllValuesFromCache
default <K,V> Iterable<V> getAllValuesFromCache(String cacheName)
Get all of the values associated with the specified cache.- Type Parameters:
K- The object type that acts as the key for the cacheV- The value that is stored in the cache- Parameters:
cacheName- the name of the cache to look in- Returns:
- the requested cache objects
-
getAllKeysFromCache
default <K,V> Iterable<K> getAllKeysFromCache(String cacheName)
Get all of the keys associated with the specified cache.- Type Parameters:
K- The object type that acts as the key for the cacheV- The value that is stored in the cache- Parameters:
cacheName- the name of the cache to look in- Returns:
- the requested cache keys
-
sizeOfCache
default int sizeOfCache(String cacheName)
Retrieve the size of the specified cache.- Parameters:
cacheName- the name of the cache- Returns:
- the size of the cache
-
clearCache
default void clearCache(String cacheName) throws CacheOperationException
Clear the contents of the specified cache.- Parameters:
cacheName- the name of the cache to clear- Throws:
CacheOperationException- if there was an error clearing the cache
-
-