Module ca.on.oicr.gsi.shesmu
Class LabelledKeyValueCache<K,L,V>
java.lang.Object
ca.on.oicr.gsi.shesmu.plugin.cache.LabelledKeyValueCache<K,L,V>
- Type Parameters:
K- the keys to use to lookup data in the cacheL- the "label" associated with a key; this allows a key's lifecycle to be different from its data'sV- the values retrievable from the cache based on state and key
public abstract class LabelledKeyValueCache<K,L,V>
extends Object
implements Owner, Iterable<Map.Entry<L,Record<V>>>
Store data that must be generated/fetched remotely and cache the results for a set period of
time.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionLabelledKeyValueCache(String name, int ttl, RecordFactory<V> recordCtor) Create a new cache -
Method Summary
Modifier and TypeMethodDescriptionstatic Stream<? extends LabelledKeyValueCache<?,?, ?>> caches()protected abstract VFetch an item from the remote service (or generate it)final VGet an item from cachefinal VGet an item from cache without updating itfinal voidinvalidate(K key) voiditerator()protected abstract LThe fixed label associated with the specified keyfinal Stringname()The name of the cache for use in monitoringfinal longttl()The time-to-live for a record in cachefinal voidttl(int ttl) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
LabelledKeyValueCache
Create a new cache- Parameters:
name- the name, as presented to Prometheusttl- the number of minutes an item will remain in cache
-
-
Method Details
-
caches
-
fetch
Fetch an item from the remote service (or generate it)- Parameters:
key- the item to be requestedlastUpdated- the last time the item was successfully fetched- Returns:
- the cached value
- Throws:
Exception- if an error occurs, the previous value will be retained
-
get
Get an item from cache- Parameters:
key- the key to use- Returns:
- the value, if it was possible to fetch; the value may be stale if the remote end-point is in an error state
-
getStale
Get an item from cache without updating it- Parameters:
key- the key to use- Returns:
- the last value that was fetched
-
invalidate
-
invalidateAll
public void invalidateAll() -
iterator
-
label
The fixed label associated with the specified key -
name
Description copied from interface:OwnerThe name of the cache for use in monitoring -
ttl
public final long ttl()Description copied from interface:OwnerThe time-to-live for a record in cache -
ttl
public final void ttl(int ttl)
-