org.sourceforge.beanindex.cache
Class SoftReferenceLRUCache

java.lang.Object
  extended byorg.sourceforge.beanindex.cache.LRUCache
      extended byorg.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

Field Summary
 
Fields inherited from class org.sourceforge.beanindex.cache.LRUCache
cacheSize, lastRemoved, LRU_BUFFER_INIT_CAPACITY, LRUBuffer, map, timeStamp
 
Constructor Summary
SoftReferenceLRUCache()
           
SoftReferenceLRUCache(int lruBufferCapacity, int cacheSize)
          it allocates a LRUBuffer to support all the beans in the repository.
 
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 org.sourceforge.beanindex.cache.LRUCache
extendLRUBuffer, getLRUCanditatePosition, getTimeStamp, refreshLRUbufferTimeStamp, removeLRUCandidate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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 -
Method Detail

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 -