org.apache.jcs.engine.memory.mru
Class MRUMemoryCache

java.lang.Object
  extended by org.apache.jcs.engine.memory.AbstractMemoryCache
      extended by org.apache.jcs.engine.memory.mru.MRUMemoryCache
All Implemented Interfaces:
java.io.Serializable, IMemoryCache, MemoryCache

public class MRUMemoryCache
extends AbstractMemoryCache

A SLOW reference management system. The most recently used items move to the front of the list and get spooled to disk if the cache hub is configured to use a disk cache.

This class is mainly for testing the hub. It also shows that use of the Collection LinkedList is far slower than JCS' own double linked list.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.jcs.engine.memory.AbstractMemoryCache
attr, cache, cacheName, cattr, chunkSize, map, status
 
Constructor Summary
MRUMemoryCache()
           
 
Method Summary
 void dumpCacheEntries()
          Dump the cache entries from first to list for debugging.
 void dumpMap()
          Dump the cache map for debugging.
 int freeElements(int numberToFree)
          This instructs the memory cache to remove the numberToFree according to its eviction policy.
 ICacheElement get(java.io.Serializable key)
          Gets an item out of the map.
 java.lang.Object[] getKeyArray()
          Get an Array of the keys for all elements in the memory cache
 ICacheElement getQuiet(java.io.Serializable key)
          Get an item from the cache without affecting its last access time or position.
 IStats getStatistics()
          Returns the historical and statistical data for a region's memory cache.
 void initialize(CompositeCache hub)
          For post reflection creation initialization
 boolean remove(java.io.Serializable key)
          Removes an item from the cache.
protected  ICacheElement spoolLastElement()
          This removes the last elemement in the list.
 void update(ICacheElement ce)
          Puts an item to the cache.
 
Methods inherited from class org.apache.jcs.engine.memory.AbstractMemoryCache
dispose, getCacheAttributes, getCacheName, getCompositeCache, getGroupKeys, getIterator, getSize, getStatus, removeAll, setCacheAttributes, waterfal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MRUMemoryCache

public MRUMemoryCache()
Method Detail

initialize

public void initialize(CompositeCache hub)
For post reflection creation initialization

Specified by:
initialize in interface IMemoryCache
Overrides:
initialize in class AbstractMemoryCache
Parameters:
hub -

update

public void update(ICacheElement ce)
            throws java.io.IOException
Puts an item to the cache.

Specified by:
update in interface IMemoryCache
Specified by:
update in class AbstractMemoryCache
Parameters:
ce -
Throws:
java.io.IOException

spoolLastElement

protected ICacheElement spoolLastElement()
This removes the last elemement in the list.

Returns:
ICacheElement if there was a last element, else null.

freeElements

public int freeElements(int numberToFree)
                 throws java.io.IOException
This instructs the memory cache to remove the numberToFree according to its eviction policy. For example, the LRUMemoryCache will remove the numberToFree least recently used items. These will be spooled to disk if a disk auxiliary is available.

Parameters:
numberToFree -
Returns:
the number that were removed. if you ask to free 5, but there are only 3, you will get 3.
Throws:
java.io.IOException

getQuiet

public ICacheElement getQuiet(java.io.Serializable key)
                       throws java.io.IOException
Get an item from the cache without affecting its last access time or position.

Specified by:
getQuiet in interface IMemoryCache
Specified by:
getQuiet in class AbstractMemoryCache
Parameters:
key - Identifies item to find
Returns:
Element matching key if found, or null
Throws:
java.io.IOException

get

public ICacheElement get(java.io.Serializable key)
                  throws java.io.IOException
Gets an item out of the map. If it finds an item, it is removed from the list and then added to the first position in the linked list.

Specified by:
get in interface IMemoryCache
Specified by:
get in class AbstractMemoryCache
Parameters:
key -
Returns:
Throws:
java.io.IOException

remove

public boolean remove(java.io.Serializable key)
               throws java.io.IOException
Removes an item from the cache.

Specified by:
remove in interface IMemoryCache
Specified by:
remove in class AbstractMemoryCache
Parameters:
key -
Returns:
Throws:
java.io.IOException

getKeyArray

public java.lang.Object[] getKeyArray()
Get an Array of the keys for all elements in the memory cache

Specified by:
getKeyArray in interface IMemoryCache
Specified by:
getKeyArray in class AbstractMemoryCache
Returns:
Object[]

dumpMap

public void dumpMap()
Dump the cache map for debugging.


dumpCacheEntries

public void dumpCacheEntries()
Dump the cache entries from first to list for debugging.


getStatistics

public IStats getStatistics()
Description copied from interface: IMemoryCache
Returns the historical and statistical data for a region's memory cache.

Specified by:
getStatistics in interface IMemoryCache
Overrides:
getStatistics in class AbstractMemoryCache
Returns:
Statistics and Infor for the Memory Cache.


Copyright © 2002-2007 Apache Software Foundation. All Rights Reserved.