|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.apache.mahout.cf.taste.impl.common.Cache<K,V>
public final class Cache<K,V>
An efficient Map-like class which caches values for keys. Values are not "put" into a Cache;
instead the caller supplies the instance with an implementation of Retriever which can load the
value for a given key.
The cache does not support null keys.
Thanks to Amila Jayasooriya for helping evaluate performance of the rewrite of this class, as part of a Google Summer of Code 2007 project.
| Nested Class Summary | |
|---|---|
static interface |
Cache.MatchPredicate<T>
Used by {#link #removeKeysMatching(Object)} to decide things that are matching. |
| Constructor Summary | |
|---|---|
Cache(Retriever<? super K,? extends V> retriever)
Creates a new cache based on the given Retriever. |
|
Cache(Retriever<? super K,? extends V> retriever,
int maxEntries)
Creates a new cache based on the given Retriever and with given maximum size. |
|
| Method Summary | |
|---|---|
void |
clear()
Clears the cache. |
V |
get(K key)
Returns cached value for a key. |
void |
remove(K key)
Uncaches any existing value for a given key. |
void |
removeKeysMatching(Cache.MatchPredicate<K> predicate)
Clears all cache entries whose key matches the given predicate. |
void |
removeValueMatching(Cache.MatchPredicate<V> predicate)
Clears all cache entries whose value matches the given predicate. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public Cache(Retriever<? super K,? extends V> retriever)
Creates a new cache based on the given Retriever.
retriever - object which can retrieve values for keys
public Cache(Retriever<? super K,? extends V> retriever,
int maxEntries)
Creates a new cache based on the given Retriever and with given maximum size.
retriever - object which can retrieve values for keysmaxEntries - maximum number of entries the cache will store before evicting some| Method Detail |
|---|
public V get(K key)
throws TasteException
Returns cached value for a key. If it does not exist, it is loaded using a Retriever.
get in interface Retriever<K,V>key - cache key
TasteException - if an exception occurs while retrieving a new cached valuepublic void remove(K key)
Uncaches any existing value for a given key.
key - cache keypublic void removeKeysMatching(Cache.MatchPredicate<K> predicate)
public void removeValueMatching(Cache.MatchPredicate<V> predicate)
public void clear()
Clears the cache.
public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||