org.jcreme.caches
Interface Cache

All Known Subinterfaces:
ModifiableCache
All Known Implementing Classes:
AggregateCache, BaseCache

public interface Cache

This is the general interface to model an object cache. This provides the methods to store and retrieve an object based on a key.

Version:
$Revision: 1.2 $
Author:
$Author: dbregeon $

Method Summary
 void addCacheListener(CacheListener listener)
          This enables to add a CacheListener to the Cache.
 void clear()
          Removes all the objects from the Cache, leaving it empty.
 java.lang.Object[] getAllObjects()
           
 java.lang.Object[] getAllObjects(java.lang.Class type)
          This is a convenience method to ensure that the array returned if has member of the correct type.
 CacheListener[] getCacheListeners()
           
 java.util.Map getMap()
          This method enables to access to the cache contents.
 int getMaxSize()
           
 java.lang.Object getObject(java.lang.Object key)
           
 CachePolicy getReplacementPolicy()
           
 int getSize()
           
 void registerAllObjects(java.util.Map m)
          This is a convenience method.
 void registerObject(java.lang.Object key, java.lang.Object value)
          Registers an object in the cache using the given key to refer to it.
 void removeCacheListener(CacheListener listener)
          This enables to remove a CacheListener to the Cache.
 void setMaxSize(int maxSize)
          Sets the maximum number of objects that will be stored in this cache.
 void unregisterObject(java.lang.Object key)
          Removes the object associated with the given key from the Cache.
 

Method Detail

setMaxSize

public void setMaxSize(int maxSize)
Sets the maximum number of objects that will be stored in this cache.

Parameters:
maxSize - the maximum size.

getReplacementPolicy

public CachePolicy getReplacementPolicy()
Returns:
the replacement policy that is used by the Cache. It determines how the Cache makes room for new objects when the maximum size is exceeded.

registerObject

public void registerObject(java.lang.Object key,
                           java.lang.Object value)
                    throws CacheFullException
Registers an object in the cache using the given key to refer to it.

Parameters:
key - the key to use to retrieve the object.
value - the object to store in the Cache.
Throws:
CacheFullException - when the Cache would exceed its maximum size and no room can be made.

unregisterObject

public void unregisterObject(java.lang.Object key)
Removes the object associated with the given key from the Cache.

Parameters:
key - the key associated to the object to be removed.

getObject

public java.lang.Object getObject(java.lang.Object key)
Parameters:
key - the key associated to the object to be retrieved.
Returns:
the object associated to the key or null if no object is associated to the key in the Cache.

getMaxSize

public int getMaxSize()
Returns:
tthe current maximum size of the cache.

getAllObjects

public java.lang.Object[] getAllObjects()
Returns:
all the objects contained in this Cache.

getAllObjects

public java.lang.Object[] getAllObjects(java.lang.Class type)
This is a convenience method to ensure that the array returned if has member of the correct type.

Parameters:
type - the type to assign to the array (this should be a type common to all the objects contained in the Cache.
Returns:
all the objects contained in this Cache.

registerAllObjects

public void registerAllObjects(java.util.Map m)
                        throws CacheFullException
This is a convenience method. It enables to add to the cache all the objects present in the map.

Parameters:
m - the map that contains the objects (and keys) to use.
Throws:
CacheFullException - when the Cache would exceed its maximum size and no room can be made.

getMap

public java.util.Map getMap()
This method enables to access to the cache contents.

Returns:
a map of the (key,value) contents of the cache.

clear

public void clear()
Removes all the objects from the Cache, leaving it empty.


getSize

public int getSize()
Returns:
the current siez of the Cache (the number of otems currently stored).

addCacheListener

public void addCacheListener(CacheListener listener)
This enables to add a CacheListener to the Cache.

Parameters:
listener - the listener to add.

removeCacheListener

public void removeCacheListener(CacheListener listener)
This enables to remove a CacheListener to the Cache.

Parameters:
listener - the listener to remove.

getCacheListeners

public CacheListener[] getCacheListeners()
Returns:
all the listeners that are attached to this Cache.


Copyright 2006 null. All Rights Reserved.