Class AbstractCache<K,V>
- Type Parameters:
K- the type of keys maintained by this cacheV- the type of mapped values
- All Implemented Interfaces:
Cache<K,V>
Cache.
This class is to extend when creating builders of cluster compatible caches.
Local caches are built with CacheBuilder.local(), one should not try implementing a local cache by any other mean.- Since:
- 3.7.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value associated with thekeyin this cache, obtaining that value from theloaderif necessary.protected voidSchedules a call to theCache.cleanUp()method, in a separate thread.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.sodius.oslc.core.cache.Cache
asMap, cleanUp, compute, getIfPresent, invalidate, invalidateAll, put
-
Constructor Details
-
AbstractCache
public AbstractCache()
-
-
Method Details
-
get
Returns the value associated with thekeyin this cache, obtaining that value from theloaderif necessary. This method provides a simple substitute for the conventional "if cached, return; otherwise create, cache and return" pattern.If the specified key is not already associated with a value, attempts to compute its value using the given mapping function and enters it into this cache. The entire method invocation is performed atomically, so the function is applied at most once per key. Some attempted update operations on this cache by other threads may be blocked while the computation is in progress, so the computation should be short and simple, and must not attempt to update any other mappings of this cache.
Warning:
loadermust not attempt to update any other mappings of this cache.Warning:
loadermust not returnnull; it may either return a non-null value or throw an exception.Important Note: contrary to the contract of the overridden method, this implementation does not guarantee the loader is applied at most once per key.
-
scheduleCleanUp
protected void scheduleCleanUp()Schedules a call to theCache.cleanUp()method, in a separate thread. Threads are created using the factory provided byThreads.getThreadFactory().Subclasses shall call this method in the implementation of
Cache.put(Object, Object)andCache.invalidate(Object), so that expired entries are removed.
-