Class AbstractLruCache
java.lang.Object
com.ibm.dtfj.corereaders.zos.util.AbstractHashMap
com.ibm.dtfj.corereaders.zos.util.AbstractLruCache
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
ObjectLruCache
This class is the superclass of the LRU cache classes. It provides the LRU (Least Recently Used)
infrastructure to map integer keys to objects or primitive values.
It acts just like a hash map except that once it has reached its maximum size, any further
puts will displace the least recently used entry. It uses a doubly linked list to keep track
of which entries are most used - an entry is moved to the front of the list every time it
is used. Note that the LRU info is lost when the cache is rehashed, but I don't think that's
a problem because once the cache reaches its maximum size (and steady state) it will no longer rehash.
- See Also:
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractLruCache
(int maxSize) Create a new AbstractLruCache. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
getIndexAndPromote
(long key) Returns the index for the value mapped by the given key.protected int
putIndexAndPromote
(long key) Get the index for a put operation.Methods declared in class com.ibm.dtfj.corereaders.zos.util.AbstractHashMap
getKeys, getKeysArray
-
Constructor Details
-
AbstractLruCache
protected AbstractLruCache(int maxSize) Create a new AbstractLruCache.- Parameters:
maxSize
- the maximum size the cache can grow to
-
-
Method Details
-
getIndexAndPromote
protected int getIndexAndPromote(long key) Returns the index for the value mapped by the given key. Also promotes this key to the most recently used.- Returns:
- the index or -1 if it cannot be found
-
putIndexAndPromote
protected int putIndexAndPromote(long key) Get the index for a put operation. Takes care of promotion and removing the LRU entry if necessary.
-