Interface Cache<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Superinterfaces:
ReadThroughCache<K,V>
Note: null keys and values are NOT supported. Although using null values may work for some
implementations, it won't work for all implementations and the behaviour may change over time.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(CacheEntryListener<K, V> listener, boolean includeValues) Adds aCacheEntryListenervoidPut an object into the cache.putIfAbsent(K key, V value) Atomically associates the specified key with the given value if it is not already associated with a value.voidremoveListener(CacheEntryListener<K, V> listener) Removes aCacheEntryListenerbooleanAtomically replaces the entry for a key only if currently mapped to a given value.Methods inherited from interface com.atlassian.cache.ReadThroughCache
containsKey, get, get, getBulk, getKeys, getName, remove, remove, removeAll
-
Method Details
-
put
Put an object into the cache. If the specified key already exists within the cache, it will be replaced by the new object.NOTE: This method should not be used on
hybridcaches that maintain consistency only by invalidating the key on other cluster nodes. Instead, such hybrid caches should useCacheLoadersemantics and supply aCacheLoaderwhen getting theCache.- Parameters:
key- the key uniquely identifying the object to be added into the cachevalue- the non-null value to be cached
-
putIfAbsent
Atomically associates the specified key with the given value if it is not already associated with a value.NOTE: This method should not be used on
hybridcaches that maintain consistency only by invalidating the key on other cluster nodes. Instead, such hybrid caches should useCacheLoadersemantics and supply aCacheLoaderwhen getting theCache.- Parameters:
key- the key with which the specified value is associatedvalue- the non-null value to be cached- Returns:
- the previous value associated with the specified key, or
nullif there was no mapping for the key
-
replace
Atomically replaces the entry for a key only if currently mapped to a given value.NOTE: Some cache backends (e.g. Ehcache) require this operation to be performed by CAS and will throw an exception when the cache is replicated
- Parameters:
key- the key with which the specified value is associatedoldValue- the value expected to be associated with the specified keynewValue- the value to be associated with the specified key- Returns:
trueif the value was replaced,falseotherwise
-
addListener
Adds aCacheEntryListener- Parameters:
listener- the listenerincludeValues- if the events sent to this listener will include old/new value. This is can be used in cases when the cost of finding these values is big (network sync) but the listener is not interested in the concrete values for events its getting. The support for this parameter is optional and implementation dependant- Throws:
UnsupportedOperationException- if not supported- Since:
- 2.4
-
removeListener
Removes aCacheEntryListener- Parameters:
listener- the listener- Throws:
UnsupportedOperationException- if not supported- Since:
- 2.4
-