Class DelegatingNullSafeBaseCache<K,V>
- java.lang.Object
-
- com.google.common.collect.ForwardingObject
-
- org.opendaylight.infrautils.caches.baseimpl.DelegatingNullSafeBaseCache<K,V>
-
- All Implemented Interfaces:
AutoCloseable
,BaseCache<K,V>
- Direct Known Subclasses:
DelegatingNullSafeCache
,DelegatingNullSafeCheckedCache
@Beta public abstract class DelegatingNullSafeBaseCache<K,V> extends com.google.common.collect.ForwardingObject implements BaseCache<K,V>
-
-
Constructor Summary
Constructors Constructor Description DelegatingNullSafeBaseCache()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Map<K,V>
asMap()
Returns a view of the entries stored in this cache as an immutable map.protected static <K> Iterable<K>
checkNonNullKeys(@Nullable Iterable<K> keys)
protected static <K,V>
com.google.common.collect.ImmutableMap<K,V>checkReturnValue(@Nullable com.google.common.collect.ImmutableMap<K,V> map)
protected static <K,V>
VcheckReturnValue(K key, @Nullable V value)
void
close()
protected abstract BaseCache<K,V>
delegate()
void
evict(K key)
Evict an entry from the cache.CacheManager
getManager()
void
put(K key, V value)
Puts a new entry into the Cache, replacing any existing one.
-
-
-
Method Detail
-
delegate
protected abstract BaseCache<K,V> delegate()
- Specified by:
delegate
in classcom.google.common.collect.ForwardingObject
-
evict
public void evict(K key)
Description copied from interface:BaseCache
Evict an entry from the cache. If the cache does not currently contain an entry under this key, then this is ignored. If it does, that entry is evicted, to be re-calculated on the next get.Use
CacheManager.evictAll()
to evict all entries of the entire cache.
-
put
public void put(K key, V value)
Description copied from interface:BaseCache
Puts a new entry into the Cache, replacing any existing one.Normally, you often never need to call this method, as in regular usage scenarios a cache API client just invokes
Cache.get(Object)
(orCheckedCache.get(Object)
, which then internally (may) use theCacheFunction
(orCheckedCacheFunction
) - without you ever having had to explicitly put something into the Cache.This method is ONLY (!) intended for "optimizations". It is useful if the code using a cache already has a key and value (e.g. following an external update notification event kind of thing) and wants to "save time" on an expected subsequent
Cache.get(Object)
(orCheckedCache.get(Object)
invoking theCacheFunction
(orCheckedCacheFunction
) unnecessarily, using this "hint" to "propose" an entry to the cache.Any code using this must expect key/value pairs that have been put into a cache to disappear at any time (e.g. when the cache is full and this key/value hasn't been used, or after a programmatic or end-user operator initiated eviction), and be able to obtain THE SAME value from the
CacheFunction
(orCheckedCacheFunction
), for the given key.Failure to implement calls to this put method consistent with the implementation of the cache's get function WILL lead to weird cache inconsistencies!
Some Cache implementations may IGNORE this "hint" method.
-
asMap
public Map<K,V> asMap()
Description copied from interface:BaseCache
Returns a view of the entries stored in this cache as an immutable map.
-
getManager
public CacheManager getManager()
- Specified by:
getManager
in interfaceBaseCache<K,V>
-
close
public void close() throws Exception
- Specified by:
close
in interfaceAutoCloseable
- Throws:
Exception
-
checkReturnValue
protected static <K,V> V checkReturnValue(K key, @Nullable V value)
-
checkReturnValue
protected static <K,V> com.google.common.collect.ImmutableMap<K,V> checkReturnValue(@Nullable com.google.common.collect.ImmutableMap<K,V> map)
-
-