de.bea.domingo.cache
Class AbstractBaseCache

java.lang.Object
  extended by de.bea.domingo.cache.AbstractBaseCache
All Implemented Interfaces:
Cache, java.io.Serializable
Direct Known Subclasses:
SimpleCache, WeakCache

public abstract class AbstractBaseCache
extends java.lang.Object
implements Cache, java.io.Serializable

Simple cache implementation using a HashMap. Note that this implementation is not synchronized. If multiple threads access this cache concurrently, and at least one of the threads modifies the cache structurally, it must be synchronized externally. (A structural modification is any operation that adds or deletes one or more mappings; merely changing the value associated with a key that an instance already contains is not a structural modification.) This is typically accomplished by synchronizing on some object that naturally encapsulates the map. If no such object exists, the map should be "wrapped" using the Collections.synchronizedMap method. This is best done at creation time, to prevent accidental unsynchronized access to the map:

 Map map = Collections.synchronizedMap(new HashMap(...));
 

Author:
Kurt Riede
See Also:
Serialized Form

Constructor Summary
AbstractBaseCache()
          Constructor.
 
Method Summary
protected abstract  java.util.Map createMap()
          Creates the map to be used with the cache.
protected  java.util.Map getMap()
          Protected getter for map attribute to allow concrete classes to access the map.
 int size()
          Returns the number of elements in this cache (its cardinality).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface de.bea.domingo.cache.Cache
clear, containsKey, get, keySet, put, remove, values
 

Constructor Detail

AbstractBaseCache

public AbstractBaseCache()
Constructor.

Method Detail

getMap

protected final java.util.Map getMap()
Protected getter for map attribute to allow concrete classes to access the map.

Returns:
the internal map

createMap

protected abstract java.util.Map createMap()
Creates the map to be used with the cache.

Concrete classes must implement this method and create a concrete map for the cache.

Returns:
a map for the cache

size

public final int size()
Returns the number of elements in this cache (its cardinality). If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Specified by:
size in interface Cache
Returns:
the number of elements in this set (its cardinality).
See Also:
Cache.size()


Domingo Java-API