com.knowgate.cache
Class LRUCachePolicy

java.lang.Object
  extended by com.knowgate.cache.LRUCachePolicy

public final class LRUCachePolicy
extends java.lang.Object

LRU Cache Policy

Implementation of a Least Recently Used cache policy.


Nested Class Summary
 class LRUCachePolicy.LRUCacheEntry
          Double linked cell used as entry in the cache list.
 class LRUCachePolicy.LRUList
          Double queued list used to store cache entries.
 
Field Summary
protected  LRUCachePolicy.LRUList m_list
          The linked list used to implement the LRU algorithm
protected  java.util.HashMap m_map
          The map holding the cached objects
protected  int m_maxCapacity
          The maximum capacity of this cache
protected  int m_minCapacity
          The minimum capacity of this cache
 
Constructor Summary
LRUCachePolicy()
          Creates a LRU cache policy object with zero cache capacity.
LRUCachePolicy(int min, int max)
          Creates a LRU cache policy object with the specified minimum and maximum capacity.
 
Method Summary
protected  void ageOut(LRUCachePolicy.LRUCacheEntry entry)
          Callback method called when the cache algorithm ages out of the cache the given entry.
protected  void cacheMiss()
          Callback method called when a cache miss happens.
protected  LRUCachePolicy.LRUCacheEntry createCacheEntry(java.lang.Object key, java.lang.Object value, long t)
          Factory method for cache entries
protected  LRUCachePolicy.LRUList createList()
          Factory method for the linked list used by this cache implementation.
 void destroy()
          Destroys the cache that is now unusable.
 void flush()
           
 java.lang.Object get(java.lang.Object key)
           
 void insert(java.lang.Object key, java.lang.Object o, long t)
           
 java.util.Set keySet()
           
 long last(java.lang.Object key)
           
 java.lang.Object peek(java.lang.Object key)
           
 void remove(java.lang.Object key)
           
 int size()
           
 void start()
          Starts this cache that is now ready to be used.
 void stop()
          Stops this cache thus flush()ing all cached objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_map

protected java.util.HashMap m_map
The map holding the cached objects


m_list

protected LRUCachePolicy.LRUList m_list
The linked list used to implement the LRU algorithm


m_maxCapacity

protected int m_maxCapacity
The maximum capacity of this cache


m_minCapacity

protected int m_minCapacity
The minimum capacity of this cache

Constructor Detail

LRUCachePolicy

public LRUCachePolicy()
Creates a LRU cache policy object with zero cache capacity.

See Also:
create()

LRUCachePolicy

public LRUCachePolicy(int min,
                      int max)
Creates a LRU cache policy object with the specified minimum and maximum capacity.

See Also:
create()
Method Detail

start

public void start()
Starts this cache that is now ready to be used.

See Also:
create(), stop()

stop

public void stop()
Stops this cache thus flush()ing all cached objects.
After this method is called, a call to start() will restart the cache.

See Also:
start(), destroy()

destroy

public void destroy()
Destroys the cache that is now unusable.
To have it working again it must be re-create()ed and re-start()ed.

See Also:
create()

keySet

public java.util.Set keySet()

last

public long last(java.lang.Object key)

get

public java.lang.Object get(java.lang.Object key)

peek

public java.lang.Object peek(java.lang.Object key)

insert

public void insert(java.lang.Object key,
                   java.lang.Object o,
                   long t)

remove

public void remove(java.lang.Object key)

flush

public void flush()

size

public int size()

createList

protected LRUCachePolicy.LRUList createList()
Factory method for the linked list used by this cache implementation.


ageOut

protected void ageOut(LRUCachePolicy.LRUCacheEntry entry)
Callback method called when the cache algorithm ages out of the cache the given entry.
The implementation here is removing the given entry from the cache.


cacheMiss

protected void cacheMiss()
Callback method called when a cache miss happens.


createCacheEntry

protected LRUCachePolicy.LRUCacheEntry createCacheEntry(java.lang.Object key,
                                                        java.lang.Object value,
                                                        long t)
Factory method for cache entries