Interface LocalCache
public interface LocalCache
Framework service injectable in components or services methods
to handle local caching.
Useful for actions when deployed in a long running instance
when actions are costly.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
Use to enrich object with meta-data (help to choice if attached object has to be removed from cache) -
Method Summary
Modifier and TypeMethodDescription<T> T
computeIfAbsent
(Class<T> expectedClass, String key, long timeoutMs, Supplier<T> value) Read or compute and save a value for a determined duration.<T> T
computeIfAbsent
(Class<T> expectedClass, String key, Predicate<LocalCache.Element> toRemove, long timeoutMs, Supplier<T> value) Read or compute and save a value for a determined duration and predicate.<T> T
computeIfAbsent
(Class<T> expectedClass, String key, Predicate<LocalCache.Element> toRemove, Supplier<T> value) Read or compute and save a value until remove predicate go to remove.<T> T
computeIfAbsent
(Class<T> expectedClass, String key, Supplier<T> value) Compute and save a value, if key not present, for undetermined duration.void
Remove a cached entry.void
evictIfValue
(String key, Object expected) Remove a cached entry if a particular value is in the cache.
-
Method Details
-
computeIfAbsent
<T> T computeIfAbsent(Class<T> expectedClass, String key, Predicate<LocalCache.Element> toRemove, long timeoutMs, Supplier<T> value) Read or compute and save a value for a determined duration and predicate.- Type Parameters:
T
- class of cached instance.- Parameters:
expectedClass
- : cached instance class.key
- : the cache key, must be unique accross the server.toRemove
- : is the object to be removed.timeoutMs
- : duration of cache value.value
- : the value provider if the cache get does a miss.- Returns:
- the cached or newly computed value.
-
computeIfAbsent
<T> T computeIfAbsent(Class<T> expectedClass, String key, Predicate<LocalCache.Element> toRemove, Supplier<T> value) Read or compute and save a value until remove predicate go to remove.- Type Parameters:
T
- class of cached instance.- Parameters:
expectedClass
- : cached instance class.key
- : the cache key, must be unique accross the server.toRemove
- : is the object to be removed.value
- : the value provider if the cache get does a miss.- Returns:
- the cached or newly computed value.
-
computeIfAbsent
Read or compute and save a value for a determined duration.- Type Parameters:
T
- class of cached instance.- Parameters:
expectedClass
- : cached instance class.key
- : the cache key, must be unique accross the server.timeoutMs
- : duration of cache value.value
- : value provider.- Returns:
- the cached or newly computed value.
-
computeIfAbsent
Compute and save a value, if key not present, for undetermined duration.- Type Parameters:
T
- class of cached instance.- Parameters:
expectedClass
- : cached instance class.key
- : the cache key, must be unique accross the server.value
- : value provider.- Returns:
- the cached or newly computed value.
-
evict
Remove a cached entry.- Parameters:
key
- key to evict.
-
evictIfValue
Remove a cached entry if a particular value is in the cache.- Parameters:
key
- key to evict.expected
- expected value activating the eviction.
-