Package uk.gov.gchq.gaffer.cache
Interface ICache<K,V>
-
- Type Parameters:
K- The object type that acts as the key for the cacheV- The value that is stored in the cache
- All Known Implementing Classes:
HashMapCache,HazelcastCache,JcsCache
public interface ICache<K,V>Interface that All cache objects must abide by so components may instantiate any implementation of a cache - no matter what cache it is.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclear()Remove all entries from the cache.Vget(K key)Retrieve the value associated with the given key.Iterable<K>getAllKeys()Get all keys present in the cache.Iterable<V>getAllValues()Get all values present in the cache.voidput(K key, V value)Add a new key-value pair to the cache.default voidputSafe(K key, V value)Add a new key-value pair to the cache, but only if there is existing entry associated with the specified key.voidremove(K key)Remove the entry associated with the specified key.default intsize()Get the size of the cache.
-
-
-
Method Detail
-
get
V get(K key) throws CacheOperationException
Retrieve the value associated with the given key.- Parameters:
key- the key to lookup in the cache- Returns:
- the value associated with the key
- Throws:
CacheOperationException- if there is an error getting the key-value pair from the cache
-
put
void put(K key, V value) throws CacheOperationException
Add a new key-value pair to the cache.- Parameters:
key- the key to addvalue- the value to add- Throws:
CacheOperationException- if there is an error adding the new key-value pair to the cache
-
putSafe
default void putSafe(K key, V value) throws OverwritingException, CacheOperationException
Add a new key-value pair to the cache, but only if there is existing entry associated with the specified key.- Parameters:
key- the key to addvalue- the value to add- Throws:
CacheOperationException- if there is an error adding the new key-value pair to the cacheOverwritingException- if the specified key already exists in the cache with a non-null value
-
remove
void remove(K key)
Remove the entry associated with the specified key.- Parameters:
key- the key of the entry to remove
-
getAllValues
Iterable<V> getAllValues()
Get all values present in the cache.- Returns:
- a
Iterablecontaining all of the cache values
-
getAllKeys
Iterable<K> getAllKeys()
Get all keys present in the cache.- Returns:
- a
Iterablecontaining all of the cache keys
-
size
default int size()
Get the size of the cache.- Returns:
- the number of entries in the caches
-
clear
void clear() throws CacheOperationExceptionRemove all entries from the cache.- Throws:
CacheOperationException- if there was an error clearing the cache
-
-