K - The type of the key of the cacheV - The type of the values in the cachepublic class Cache<K,V> extends Object implements Computable<K,V>
| Modifier and Type | Class and Description |
|---|---|
static interface |
Cache.CycleHandler<K>
Should a cycle be detected during computation of a value
for given key, this interface allows client code to register
a callback that would get invoked in such a case.
|
| Constructor and Description |
|---|
Cache(Computable<K,V> computable)
Create new cache with given computable to compute values.
|
Cache(Computable<K,V> computable,
Cache.CycleHandler<K> cycleHandler)
Create new cache with given computable and cycle handler.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Empty cache.
|
V |
compute(K key)
Defines an expensive computation to retrieve value V from key K.
|
boolean |
containsKey(K key)
Returns true if the key has already been cached.
|
void |
remove(K key)
Remove item from the cache.
|
int |
size()
Returns the size of the cache
|
public Cache(Computable<K,V> computable)
computable - public Cache(Computable<K,V> computable, Cache.CycleHandler<K> cycleHandler)
computable - cycleHandler - public V compute(K key)
Computablecompute in interface Computable<K,V>key - input data.public void clear()
public boolean containsKey(K key)
key - public void remove(K key)
key - item key.public int size()
Copyright © 2009–2014 Oracle Corporation. All rights reserved.