|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectCache<K,V>
public abstract class Cache<K,V>
Cache is an abstract class used for code shared by SimpleCache and GeneratingCache. Contains the workhorse functions for maintaining a cache, expiring entries based on age or count, checking dependencies, and checking for a key.
Nested Class Summary | |
---|---|
protected class |
Cache.ListEntry
An entry in the age list maintained by the cache |
protected class |
Cache.NullIterator
Used to return an iterator that does nothing |
Field Summary | |
---|---|
protected EmbeddedList |
ageList
A list, kept sorted by descending age, of all the entries. |
protected HashMap<K,Cache.ListEntry> |
keyMap
Maintains a mapping of key to ListEntry, for fast key lookups |
private int |
maxEntries
Maximum number of entries the cache may contain |
private int |
maxTime
Maximum amount of time (in seconds) an entry can stay in the cache without being used. |
Constructor Summary | |
---|---|
Cache(int maxEntries,
int maxTime)
Constructor - sets up the parameters of the cache. |
Method Summary | |
---|---|
protected void |
cleanup()
Maintains the maxEntries and maxTime constraints imposed on the cache. |
void |
clear()
Remove all entries from the cache. |
boolean |
dependenciesValid(K key)
Check the dependencies of a cache entry, if present. |
Iterator |
getDependencies(K key)
Get the list of dependencies for a cache entry, if present. |
boolean |
has(K key)
Checks if the cache currently contains an entry for the given key. |
long |
lastSet(K key)
Gets the time the entry for the given key was created, or zero if the key isn't present. |
protected void |
logAction(String action,
K key,
V value)
Derived classes can override this method to print out log messages when significant things happen (entries are added, removed, expired, etc.) |
V |
remove(K key)
Remove an entry from the cache. |
int |
size()
Tells how many entries are currently cached |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private int maxEntries
private int maxTime
protected HashMap<K,Cache.ListEntry> keyMap
protected EmbeddedList ageList
Constructor Detail |
---|
public Cache(int maxEntries, int maxTime)
maxEntries
- Number of entries allowed. If additional entries
are created, older ones will be removed. Zero
means no limit.maxTime
- Time (in seconds) that a cache entry will remain.
If the entry hasn't been used in that time, it
is removed from the cache. Zero means no time
limit.Method Detail |
---|
public boolean has(K key)
key
- The key to look for.
public long lastSet(K key)
key
- The key to look for
public boolean dependenciesValid(K key)
key
- The key to check
public Iterator getDependencies(K key)
key
- The key to check
public V remove(K key)
key
- The key to look up
public void clear()
public int size()
protected void cleanup()
protected void logAction(String action, K key, V value)
action
- What happened ("Added", "Removed", etc.)key
- The key involved in the actionvalue
- The value involved in the action
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |