|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.sourceforge.beanindex.cache.LRUCache
A simple LRU Cache abstract class for implementation. It uses int array as a buffer to record the hit timestamp. Also it does not use the System time as the timestamp. To save memory it generates a timestamp of int type. each hit increments the timestamp by one.
Field Summary | |
protected int |
cacheSize
|
protected int |
lastRemoved
|
protected static int |
LRU_BUFFER_INIT_CAPACITY
|
protected int[] |
LRUBuffer
|
protected java.util.Map |
map
|
protected int |
timeStamp
|
Constructor Summary | |
LRUCache()
|
Method Summary | |
protected void |
extendLRUBuffer(int location)
|
abstract java.lang.Object |
get(int key)
gets the bean out of cache if exists. |
protected int |
getLRUCanditatePosition()
finds the LRU candidate position by traversing the LRUBuffer Could not think of any other better way at this point.It is a leaner search. |
protected int |
getTimeStamp()
A custom timestamp to be used for LRUbuffer. |
abstract void |
put(int key,
java.lang.Object obj)
put the key, value pair in to cache. |
protected void |
refreshLRUbufferTimeStamp()
This method refreshes the LRU Timestamp buffer to the min value in the buffer |
protected void |
removeLRUCandidate()
This method removes the LRU Candidate from the cache. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final int LRU_BUFFER_INIT_CAPACITY
protected int[] LRUBuffer
protected int cacheSize
protected int timeStamp
protected int lastRemoved
protected java.util.Map map
Constructor Detail |
public LRUCache()
Method Detail |
public abstract java.lang.Object get(int key)
key
-
public abstract void put(int key, java.lang.Object obj)
key
- obj
- protected int getTimeStamp()
protected void removeLRUCandidate()
protected int getLRUCanditatePosition()
protected void refreshLRUbufferTimeStamp()
protected void extendLRUBuffer(int location)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |