org.apache.jcs.engine.memory.lru
Class LHMLRUMemoryCache<K extends Serializable,V extends Serializable>

java.lang.Object
  extended by org.apache.jcs.engine.memory.AbstractMemoryCache<K,V>
      extended by org.apache.jcs.engine.memory.lru.LHMLRUMemoryCache<K,V>
All Implemented Interfaces:
Serializable, IRequireScheduler, IMemoryCache<K,V>

public class LHMLRUMemoryCache<K extends Serializable,V extends Serializable>
extends AbstractMemoryCache<K,V>

This is a test memory manager using the jdk1.4 LinkedHashMap.

See Also:
Serialized Form

Nested Class Summary
 class LHMLRUMemoryCache.LHMSpooler
          Implementation of removeEldestEntry in LinkedHashMap
 
Field Summary
protected  int hitCnt
          number of hits
protected static org.apache.commons.logging.Log log
          The Logger.
protected  int missCnt
          number of misses
protected  int putCnt
          number of puts
 
Fields inherited from class org.apache.jcs.engine.memory.AbstractMemoryCache
cache, cacheAttributes, cacheName, chunkSize, elementAttributes, map, status
 
Constructor Summary
LHMLRUMemoryCache()
           
 
Method Summary
 Map<K,MemoryElementDescriptor<K,V>> createMap()
          Returns a synchronized LHMSpooler
 void dumpCacheEntries()
          Dump the cache entries from first to last for debugging.
 int freeElements(int numberToFree)
          This can't be implemented.
 ICacheElement<K,V> get(K key)
          Get an item from the cache
 Set<K> getKeySet()
          Get an Array of the keys for all elements in the memory cache
 ICacheElement<K,V> getQuiet(K key)
          Get an item from the cache without affecting its last access time or position.
 IStats getStatistics()
          This returns semi-structured information on the memory cache, such as the size, put count, hit count, and miss count.
 void initialize(CompositeCache<K,V> hub)
          For post reflection creation initialization
 boolean remove(K key)
          Removes an item from the cache.
 void update(ICacheElement<K,V> ce)
          Puts an item to the cache.
 
Methods inherited from class org.apache.jcs.engine.memory.AbstractMemoryCache
dispose, dumpMap, getCacheAttributes, getCacheName, getCompositeCache, getGroupKeys, getGroupNames, getIterator, getMultiple, getSize, getStatus, removeAll, setCacheAttributes, setScheduledExecutorService, waterfal
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log
The Logger.


hitCnt

protected int hitCnt
number of hits


missCnt

protected int missCnt
number of misses


putCnt

protected int putCnt
number of puts

Constructor Detail

LHMLRUMemoryCache

public LHMLRUMemoryCache()
Method Detail

initialize

public void initialize(CompositeCache<K,V> hub)
For post reflection creation initialization

Specified by:
initialize in interface IMemoryCache<K extends Serializable,V extends Serializable>
Overrides:
initialize in class AbstractMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
hub -

createMap

public Map<K,MemoryElementDescriptor<K,V>> createMap()
Returns a synchronized LHMSpooler

Specified by:
createMap in class AbstractMemoryCache<K extends Serializable,V extends Serializable>
Returns:
Collections.synchronizedMap( new LHMSpooler() )

update

public void update(ICacheElement<K,V> ce)
            throws IOException
Puts an item to the cache.

Specified by:
update in interface IMemoryCache<K extends Serializable,V extends Serializable>
Specified by:
update in class AbstractMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
ce - Description of the Parameter
Throws:
IOException

getQuiet

public ICacheElement<K,V> getQuiet(K key)
                                                                      throws IOException
Get an item from the cache without affecting its last access time or position. There is no way to do this with the LinkedHashMap!

Specified by:
getQuiet in interface IMemoryCache<K extends Serializable,V extends Serializable>
Overrides:
getQuiet in class AbstractMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
key - Identifies item to find
Returns:
Element matching key if found, or null
Throws:
IOException

get

public ICacheElement<K,V> get(K key)
                                                                 throws IOException
Get an item from the cache

Specified by:
get in interface IMemoryCache<K extends Serializable,V extends Serializable>
Specified by:
get in class AbstractMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
key - Identifies item to find
Returns:
ICacheElement if found, else null
Throws:
IOException

remove

public boolean remove(K key)
               throws IOException
Removes an item from the cache. This method handles hierarchical removal. If the key is a String and ends with the CacheConstants.NAME_COMPONENT_DELIMITER, then all items with keys starting with the argument String will be removed.

Specified by:
remove in interface IMemoryCache<K extends Serializable,V extends Serializable>
Specified by:
remove in class AbstractMemoryCache<K extends Serializable,V extends Serializable>
Parameters:
key -
Returns:
true if removed
Throws:
IOException

getKeySet

public Set<K> getKeySet()
Get an Array of the keys for all elements in the memory cache

Specified by:
getKeySet in interface IMemoryCache<K extends Serializable,V extends Serializable>
Specified by:
getKeySet in class AbstractMemoryCache<K extends Serializable,V extends Serializable>
Returns:
An Object[]

getStatistics

public IStats getStatistics()
This returns semi-structured information on the memory cache, such as the size, put count, hit count, and miss count.

Specified by:
getStatistics in interface IMemoryCache<K extends Serializable,V extends Serializable>
Overrides:
getStatistics in class AbstractMemoryCache<K extends Serializable,V extends Serializable>
Returns:
IStats

dumpCacheEntries

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


freeElements

public int freeElements(int numberToFree)
                 throws IOException
This can't be implemented.

Parameters:
numberToFree -
Returns:
0
Throws:
IOException


Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.