net.sf.swarmcache
Class AutoCache

java.lang.Object
  |
  +--net.sf.swarmcache.AutoCache
All Implemented Interfaces:
ObjectCache

public class AutoCache
extends java.lang.Object
implements ObjectCache

This cache implementation uses soft references so that cached objects are automatically garbage collected when needed. Note that this maximizes the cache size at the expense of making no guarantees as to the cache-clearing algorithm used. So, it makes for good memory use at the possible expense of cache hit frequency.

Author:
John Watkinson

Constructor Summary
AutoCache()
          Default contsructor required.
AutoCache(java.lang.String cacheType)
           
 
Method Summary
 java.lang.Object clear(java.io.Serializable key)
          Clears an object from the cache by key.
 void clearAll()
          Clears the entire cache.
 java.lang.Object get(java.io.Serializable key)
          Gets an object from the cache by key, or returns null if that object is not cached.
 java.lang.String getType()
          Gets the common name of the type of objects to cache.
 void put(java.io.Serializable key, java.lang.Object object)
          Adds an object to the cache.
 void setType(java.lang.String cacheType)
          Sets the common name of the type of objects to cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutoCache

public AutoCache()
Default contsructor required.


AutoCache

public AutoCache(java.lang.String cacheType)
Method Detail

setType

public void setType(java.lang.String cacheType)
Sets the common name of the type of objects to cache.

Specified by:
setType in interface ObjectCache

getType

public java.lang.String getType()
Description copied from interface: ObjectCache
Gets the common name of the type of objects to cache.

Specified by:
getType in interface ObjectCache

put

public void put(java.io.Serializable key,
                java.lang.Object object)
Adds an object to the cache.

Specified by:
put in interface ObjectCache

get

public java.lang.Object get(java.io.Serializable key)
Description copied from interface: ObjectCache
Gets an object from the cache by key, or returns null if that object is not cached.

Specified by:
get in interface ObjectCache

clear

public java.lang.Object clear(java.io.Serializable key)
Description copied from interface: ObjectCache
Clears an object from the cache by key.

Specified by:
clear in interface ObjectCache

clearAll

public void clearAll()
Description copied from interface: ObjectCache
Clears the entire cache.

Specified by:
clearAll in interface ObjectCache