iitb.con.caching
Class LRUCache<K>

java.lang.Object
  extended by iitb.con.caching.LRUCache<K>
All Implemented Interfaces:
Cache<K>

public class LRUCache<K>
extends java.lang.Object
implements Cache<K>

LRU cache. The least recently used objects are replaced when the cache is full.


Field Summary
 int MAX_ENTRIES
          Maximum entries in the cache
 
Constructor Summary
LRUCache()
           
LRUCache(int maxEntries)
           
 
Method Summary
 void clear()
          Clears the cache
 long freeSpace()
          Returns the available free space
 CacheObject get(K key)
          Returns the cached object for the given key
 long getSize()
          Returns the size of cache in bytes
 boolean put(K key, CacheObject object)
          Places the cache object in the cache using the key
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_ENTRIES

public int MAX_ENTRIES
Maximum entries in the cache

Constructor Detail

LRUCache

public LRUCache()

LRUCache

public LRUCache(int maxEntries)
Method Detail

clear

public void clear()
Clears the cache

Specified by:
clear in interface Cache<K>

freeSpace

public long freeSpace()
Returns the available free space

Specified by:
freeSpace in interface Cache<K>
Returns:
cache free space

get

public CacheObject get(K key)
Returns the cached object for the given key

Specified by:
get in interface Cache<K>
Parameters:
key - key used to retrieve the object
Returns:
cached object if present, else returns NULL
See Also:
CacheObject

getSize

public long getSize()
Returns the size of cache in bytes

Specified by:
getSize in interface Cache<K>
Returns:
cache size as long

put

public boolean put(K key,
                   CacheObject object)
Places the cache object in the cache using the key

Specified by:
put in interface Cache<K>
Parameters:
key - key used to place the object
object - cache object
Returns:
true on success
See Also:
CacheObject