Package de.intarsys.tools.cache
Class Cache<T>
java.lang.Object
de.intarsys.tools.cache.Cache<T>
- All Implemented Interfaces:
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all entries in the cache.The object with the key "key" or null.booleantrueif the component is out of synch.voidStore the object "value" with the key "key" in the cache.voidRemove an object from the cache.protected voidPerform the "cleanup" of the cache.intsize()The actual size of the cache.voidsynch()Perform a synchronization with the components physical resources.
-
Constructor Details
-
Cache
public Cache(int size) Create a cache with a maximum size of size elements.- Parameters:
size- The maximum number of elements held in the cache.
-
-
Method Details
-
clear
public void clear()Clear all entries in the cache. -
get
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
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
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
-