de.netseeker.ejoe.cache
Class SoftKeyedObjectCache

java.lang.Object
  extended byde.netseeker.ejoe.cache.SoftKeyedObjectCache

public final class SoftKeyedObjectCache
extends java.lang.Object

A keyed value cache implementation that uses soft references to store cached values. Once a value got garbage collected by the JVM, the associated key-value pair will be removed by the next put() or get() operation.

Author:
netseeker

Constructor Summary
SoftKeyedObjectCache()
          Create a new cache which will store max. 10000 objects.
SoftKeyedObjectCache(int size)
          Create a new cache of the given size.
 
Method Summary
 java.lang.Object get(java.lang.Object key)
          Returns an entry from this cache
 void put(java.lang.Object key, java.lang.Object obj)
          Adds a new entry to this cache under the given key
 java.lang.Object remove(java.lang.Object key)
          Removes the given key and it's associated value from this cache
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SoftKeyedObjectCache

public SoftKeyedObjectCache()
Create a new cache which will store max. 10000 objects. If the cache reaches max. size it will ditch some of the oldest key-value pairs by each put operation


SoftKeyedObjectCache

public SoftKeyedObjectCache(int size)
Create a new cache of the given size. If the cache reaches max. size it will ditch some of the oldest key-value pairs by each put operation

Parameters:
size - max. amount of objects to hold in this cache
Method Detail

put

public void put(java.lang.Object key,
                java.lang.Object obj)
Adds a new entry to this cache under the given key

Parameters:
key - identifier under which the given object will be found in this cache
obj - object to cache

get

public java.lang.Object get(java.lang.Object key)
Returns an entry from this cache

Parameters:
key -
Returns:
object that is cached under the given key or null if either no object is cached under the given key, or an object was cached under the given key but is already garbage collected

remove

public java.lang.Object remove(java.lang.Object key)
Removes the given key and it's associated value from this cache

Parameters:
key -
Returns:
the removed value or null


Copyright © 2005-2006 netseeker. All Rights Reserved.