public class MRU extends java.lang.Object implements CachePolicy
Modifier and Type | Field and Description |
---|---|
(package private) CacheEntry |
_first
Beginning of linked-list of cache elements.
|
(package private) java.util.Hashtable |
_hash
Cached object hashtable
|
(package private) CacheEntry |
_last
End of linked-list of cache elements.
|
(package private) int |
_max
Maximum number of objects in the cache.
|
(package private) java.util.Vector |
listeners
Cache eviction listeners
|
Constructor and Description |
---|
MRU(int max)
Construct an MRU with a given maximum number of objects.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addEntry(CacheEntry entry)
Add a CacheEntry.
|
void |
addListener(CachePolicyListener listener)
Add a listener to this cache policy
|
java.util.Enumeration |
elements()
Enumerate elements' values in the cache
|
java.lang.Object |
get(java.lang.Object key)
Obtain an object in the cache
|
protected CacheEntry |
purgeEntry()
Purge least recently used object from the cache
|
void |
put(java.lang.Object key,
java.lang.Object value)
Place an object in the cache.
|
void |
remove(java.lang.Object key)
Remove an object from the cache
|
void |
removeAll()
Remove all objects from the cache
|
protected void |
removeEntry(CacheEntry entry)
Remove a CacheEntry from linked list
|
void |
removeListener(CachePolicyListener listener)
Remove a listener from this cache policy
|
protected void |
touchEntry(CacheEntry entry)
Place entry at the end of linked list -- Most Recently Used
|
java.util.Hashtable _hash
int _max
CacheEntry _first
CacheEntry _last
java.util.Vector listeners
public void put(java.lang.Object key, java.lang.Object value) throws CacheEvictionException
put
in interface CachePolicy
key
- key for the cached objectvalue
- the cached objectCacheEvictionException
- propagated if, while evicting objects
to make room for new object, an eviction listener encountered
this problem.public java.lang.Object get(java.lang.Object key)
get
in interface CachePolicy
key
- key the object was cached underpublic void remove(java.lang.Object key)
remove
in interface CachePolicy
key
- key the object was stored in the cache under.public void removeAll()
removeAll
in interface CachePolicy
public java.util.Enumeration elements()
elements
in interface CachePolicy
public void addListener(CachePolicyListener listener)
addListener
in interface CachePolicy
listener
- Listener to add to this policypublic void removeListener(CachePolicyListener listener)
removeListener
in interface CachePolicy
listener
- Listener to remove from this policyprotected void addEntry(CacheEntry entry)
protected void removeEntry(CacheEntry entry)
protected void touchEntry(CacheEntry entry)
protected CacheEntry purgeEntry() throws CacheEvictionException
CacheEvictionException
Cees de Groot (C) 2000-2001. All rights reserved http://jdbm.sourceforge.net