org.sourceforge.beanindex.cache
Class SoftReferenceLRUCache
java.lang.Object
org.sourceforge.beanindex.cache.LRUCache
org.sourceforge.beanindex.cache.SoftReferenceLRUCache
- public final class SoftReferenceLRUCache
- extends LRUCache
A simple LRU Cache 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.
- Author:
- Sakthivel Muthusamy
Method Summary |
java.lang.Object |
get(int beanId)
gets the bean out of cache if exists. |
void |
put(int key,
java.lang.Object obj)
put the key, value pair in to cache. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SoftReferenceLRUCache
public SoftReferenceLRUCache()
SoftReferenceLRUCache
public SoftReferenceLRUCache(int lruBufferCapacity,
int cacheSize)
- it allocates a LRUBuffer to support all the beans in the repository.
limit is applied at runtime for the cache only.
- Parameters:
lruBufferCapacity
- cacheSize
-
get
public final java.lang.Object get(int beanId)
- gets the bean out of cache if exists. It updates the LRUbuffer with the
recent timestamp if the bean exists in cache.
- Specified by:
get
in class LRUCache
- Parameters:
beanId
-
- Returns:
- Object
put
public final void put(int key,
java.lang.Object obj)
- put the key, value pair in to cache. Note the id is a primitivie type.
This helps to index the LRUbuffer easily.
- Specified by:
put
in class LRUCache
- Parameters:
key
- obj
-