|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.jopendocument.util.cache.ICache<K,V,D>
K
- key type, eg String.V
- value type, eg List of SQLRow.D
- source data type, eg SQLTable.public class ICache<K,V,D>
To keep results computed from some data. The results will be automatically invalidated after some period of time or when the data is modified.
Constructor Summary | |
---|---|
ICache()
|
|
ICache(int delay)
|
|
ICache(int delay,
int size)
|
|
ICache(int delay,
int size,
String name)
Creates a cache with the given parameters. |
Method Summary | |
---|---|
void |
addRunning(K key)
Tell this cache that we're in process of getting the value for key, so if someone else ask have them wait. |
CacheResult<V> |
check(K key)
Check if key is in cache, in that case returns the value otherwise adds key to running and returns NOT_IN_CACHE . |
void |
clear()
|
void |
clear(K select)
|
CacheResult<V> |
get(K sel)
If sel is in cache returns its value, else if key is running block until the key
is put (or the current thread is interrupted). |
ICache<K,V,D> |
getParent()
|
boolean |
isRunning(K sel)
|
void |
put(K sel,
V res)
Put a result which doesn't depend on variable data in this cache. |
Set<? extends CacheWatcher<K,D>> |
put(K sel,
V res,
Set<? extends D> data)
Put a result in this cache. |
void |
removeRunning(K key)
|
void |
setParent(ICache<K,V,D> parent)
Allow to continue the search for a key in another instance. |
void |
setWatcherFactory(CacheWatcherFactory<K,D> f)
|
int |
size()
|
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ICache()
public ICache(int delay)
public ICache(int delay, int size)
public ICache(int delay, int size, String name)
delay
- the delay in seconds before a key is cleared.size
- the maximum size of the cache, negative means no limit.name
- name of this cache and associated thread.
IllegalArgumentException
- if size is 0.Method Detail |
---|
public final void setWatcherFactory(CacheWatcherFactory<K,D> f)
public final void setParent(ICache<K,V,D> parent)
parent
- the cache to search when a key isn't found in this.public final ICache<K,V,D> getParent()
public final CacheResult<V> get(K sel)
sel
is in cache returns its value, else if key is running block until the key
is put (or the current thread is interrupted). Then if a parent
has been set, use it. Otherwise the key is not in cache so return a CacheResult of state
CacheResult.State.NOT_IN_CACHE
.
sel
- the key we're getting the value for.
public final void addRunning(K key)
key
- the key we're getting the value for.put(Object, Object, Set)
public final void removeRunning(K key)
public final boolean isRunning(K sel)
public final CacheResult<V> check(K key)
NOT_IN_CACHE
.
key
- the key to be checked.
null
.addRunning(Object)
public final void put(K sel, V res)
sel
- the key.res
- the result associated with sel
.public final Set<? extends CacheWatcher<K,D>> put(K sel, V res, Set<? extends D> data)
sel
- the key.res
- the result associated with sel
.data
- the data from which res
is computed.
public final void clear(K select)
public final void clear()
public final int size()
public final String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |