org.apache.slide.util
Class HashMapObjectCache

java.lang.Object
  |
  +--org.apache.slide.util.AbstractObjectCache
        |
        +--org.apache.slide.util.HashMapObjectCache
All Implemented Interfaces:
ObjectCache

public class HashMapObjectCache
extends AbstractObjectCache

Object cache implementation using Keith Visco's HashMap structure.

Version:
$Revision: 1.6 $ $Date: 2000/09/26 02:44:28 $
Author:
Remy Maucherat

Field Summary
protected  HashMap cache
          Cache structure.
 
Fields inherited from class org.apache.slide.util.AbstractObjectCache
cacheHits, cacheRequests, currentHitRatio, DEFAULT_HIT_RATIO, DEFAULT_SIZE, desiredHitRatio, initialSize, maxSize
 
Constructor Summary
HashMapObjectCache()
          Constructor.
HashMapObjectCache(int initialSize, int maxSize, double desiredHitRatio)
          Constructor.
 
Method Summary
 void clear()
          Clear object cache.
 java.lang.Object get(java.lang.Object key)
          Get the object associated with the key.
protected  int getSize()
          Get cache size.
 void put(java.lang.Object key, java.lang.Object value)
          Add an object to the cache, or overwrite its value.
 void remove(java.lang.Object key)
          Remove object associated with the given key.
protected  void removeSomeObjects()
          Removes some elements from the cache.
protected  void resize()
          Resize cache.
 
Methods inherited from class org.apache.slide.util.AbstractObjectCache
shouldResize
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected HashMap cache
Cache structure.
Constructor Detail

HashMapObjectCache

public HashMapObjectCache()
Constructor.

Warning (blinking) : That constructor is to be used really carefully as the cache maximum size is not limited.


HashMapObjectCache

public HashMapObjectCache(int initialSize,
                          int maxSize,
                          double desiredHitRatio)
Constructor.
Parameters:
initialSize - Initial size of the cache
maxSize - Maximum size of the cache
desiredHitRatio - Desired cache hit ratio
Method Detail

get

public java.lang.Object get(java.lang.Object key)
Get the object associated with the key.
Overrides:
get in class AbstractObjectCache
Parameters:
key - Object's key
Returns:
Object null if there is no object associated with that key in the cache, or the object value otherwise

put

public void put(java.lang.Object key,
                java.lang.Object value)
Add an object to the cache, or overwrite its value.
Overrides:
put in class AbstractObjectCache
Parameters:
key - Object's key
object - Object's value

remove

public void remove(java.lang.Object key)
Remove object associated with the given key. Doesn't do anything if the key wasn't associated with any object.
Overrides:
remove in class AbstractObjectCache
Parameters:
key - Object's key

clear

public void clear()
Clear object cache.
Overrides:
clear in class AbstractObjectCache

removeSomeObjects

protected void removeSomeObjects()
Removes some elements from the cache. The selection of the objects to remove, along with the number are left to the implementation.
Overrides:
removeSomeObjects in class AbstractObjectCache

getSize

protected int getSize()
Get cache size.
Overrides:
getSize in class AbstractObjectCache
Returns:
int Current cache size

resize

protected void resize()
Resize cache.
Overrides:
resize in class AbstractObjectCache