Package de.intarsys.tools.cache
Class Cache<T>
- java.lang.Object
-
- de.intarsys.tools.cache.Cache<T>
-
- All Implemented Interfaces:
ISynchronizable
public class Cache<T> extends java.lang.Object implements ISynchronizable
A very simple cache implementation. The cache supports "null" entries.The cache strategy depends on the samples taken in the CacheEntry.
-
-
Constructor Summary
Constructors Constructor Description Cache(int size)Create a cache with a maximum size of size elements.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clear all entries in the cache.Tget(java.lang.Object key)The object with the key "key" or null.booleanisOutOfSynch()trueif the component is out of synch.voidput(java.lang.Object key, T value)Store the object "value" with the key "key" in the cache.voidremove(java.lang.Object key)Remove an object from the cache.protected voidremoveStrategy()Perform the "cleanup" of the cache.intsize()The actual size of the cache.voidsynch()Perform a synchronization with the components physical resources.
-
-
-
Method Detail
-
clear
public void clear()
Clear all entries in the cache.
-
get
public T get(java.lang.Object key)
The object with the key "key" or null.- Parameters:
key- The key to be used for looking up the cache.- Returns:
- The object with the key "key" or null.
-
isOutOfSynch
public boolean isOutOfSynch()
Description copied from interface:ISynchronizabletrueif the component is out of synch.- Specified by:
isOutOfSynchin interfaceISynchronizable- Returns:
trueif the component is out of synch.
-
put
public void put(java.lang.Object key, T value)Store the object "value" with the key "key" in the cache.- Parameters:
key- The key to use for storing the objectvalue- The value to put in the cache.
-
remove
public void remove(java.lang.Object key)
Remove an object from the cache.- Parameters:
key-
-
removeStrategy
protected void removeStrategy()
Perform the "cleanup" of the cache. The "least valuable" cache entry is removed.
-
size
public int size()
The actual size of the cache.- Returns:
- The actual size of the cache.
-
synch
public void synch()
Description copied from interface:ISynchronizablePerform a synchronization with the components physical resources.In case of a scheduled synchronization this may be called by an external daemon.
- Specified by:
synchin interfaceISynchronizable
-
-