public class ReadThroughCache<K,V> extends Object
Note that the cache itself implements the #Retriever
interface; caches may be
stacked.
Modifier and Type | Class and Description |
---|---|
static interface |
ReadThroughCache.Retriever<KK,VV>
This interface defines the retrieval operation: given a key, it will return a value.
|
static class |
ReadThroughCache.Synchronization
Options for controlling concurrent retrieval.
|
Constructor and Description |
---|
ReadThroughCache(int size,
ReadThroughCache.Retriever<K,V> retriever)
Convenience constructor: creates an instance with specified size and retriever,
using per-key synchronization.
|
ReadThroughCache(int size,
ReadThroughCache.Retriever<K,V> retriever,
ReadThroughCache.Synchronization syncOpt)
Base constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Removes all cached values.
|
V |
retrieve(K key) |
int |
size()
Returns the count of mappings currently in the cache.
|
public ReadThroughCache(int size, ReadThroughCache.Retriever<K,V> retriever, ReadThroughCache.Synchronization syncOpt)
size
- Maximum number of items in the cache; the least recently used
item will be evicted if retrieval would exceed this limit. To
prevent resizing the underlying hash table, this value is also
used as the map's capacity.retriever
- The function to retrieve items.syncOpt
- The synchronization strategy.public ReadThroughCache(int size, ReadThroughCache.Retriever<K,V> retriever)
public V retrieve(K key) throws InterruptedException
InterruptedException
public int size()
public void clear()