K
- The type of the key of the cacheV
- The type of the values in the cachepublic class Cache<K,V> extends Object implements Function<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(Function<K,V> computable)
Create new cache with given computable to compute values.
|
Cache(Function<K,V> computable,
Cache.CycleHandler<K> cycleHandler)
Create new cache with given computable and cycle handler.
|
Modifier and Type | Method and Description |
---|---|
V |
apply(K key) |
void |
clear()
Empty cache.
|
boolean |
containsKey(K key)
Returns true if the key has already been cached.
|
Enumeration<K> |
keys()
Get the cache keys
|
void |
remove(K key)
Remove item from the cache.
|
int |
size()
Returns the size of the cache
|
public Cache(Function<K,V> computable)
computable
- function generated the new value.public Cache(Function<K,V> computable, Cache.CycleHandler<K> cycleHandler)
computable
- function generated the new value.cycleHandler
- handler used if the thread cycle is met.public void clear()
public Enumeration<K> keys()
public boolean containsKey(K key)
key
- item key.public void remove(K key)
key
- item key.public int size()
Copyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.