iitb.con.caching
Class MRUCache<K>

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

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

MRU cache. The most recently used objects are replaced when the cache is full.


Constructor Summary
MRUCache(long cacheSize)
          Initializes the cache with specified size
 
Method Summary
 void clear()
          Clears the cache
 long freeSpace()
          Returns the available free space
 CacheObject get(K key)
          Returns the instance from the cache for the given instance id
 long getSize()
          Returns the size of cache in bytes
 boolean put(K key, CacheObject obj)
          Places the instance into the cache
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MRUCache

public MRUCache(long cacheSize)
Initializes the cache with specified size

Parameters:
cacheSize - cache size in bytes
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 instance from the cache for the given instance id

Specified by:
get in interface Cache<K>
Parameters:
key - key used to retrieve the object
Returns:
Instance if present in cache or else return 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 obj)
Places the instance into the cache

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