org.apache.commons.cache
Class BaseCache

java.lang.Object
  extended by org.apache.commons.cache.BaseCache
All Implemented Interfaces:
Serializable, Cache
Direct Known Subclasses:
NoOpCache, SimpleCache

public abstract class BaseCache
extends Object
implements Cache

An abstract base Cache implementation, managing the registration of listeners and the broadcast of events.

Version:
$Id: BaseCache.java 155435 2005-02-26 13:17:27Z dirkv $
Author:
Rodney Waldhoff
See Also:
Serialized Form

Field Summary
protected  ArrayList _retrievalListeners
          My list of RetrievalListeners.
protected  ArrayList _storageListeners
          My list of StorageListeners.
 
Constructor Summary
BaseCache()
           
 
Method Summary
protected  void broadcastCleared()
          Broadcast a StorageListener.cleared() event to my set of StorageListeners.
protected  void broadcastCleared(Serializable key)
          Broadcast a StorageListener.cleared(java.io.Serializable) event to my set of StorageListeners.
protected  void broadcastNotRetrieved(Serializable key)
          Broadcast a RetrievalListener.notRetrieved(java.io.Serializable) event to my set of RetrievalListeners.
protected  void broadcastNotStored(Serializable key, Serializable val, Long expiresAt, Long cost, Serializable group)
          Broadcast a StorageListener.notStored(java.io.Serializable,java.io.Serializable,java.lang.Long,java.lang.Long,java.io.Serializable) event to my set of StorageListeners.
protected  void broadcastRetrieved(Serializable key)
          Broadcast a RetrievalListener.retrieved(java.io.Serializable) event to my set of RetrievalListeners.
protected  void broadcastRetrieveRequested(Serializable key)
          Broadcast a RetrievalListener.retrieveRequested(java.io.Serializable) event to my set of RetrievalListeners.
protected  void broadcastStored(Serializable key, Serializable val, Long expiresAt, Long cost, Serializable group)
          Broadcast a StorageListener.stored(java.io.Serializable,java.io.Serializable,java.lang.Long,java.lang.Long,java.io.Serializable) event to my set of StorageListeners.
protected  void broadcastStoreRequested(Serializable key, Serializable val, Long expiresAt, Long cost, Serializable group)
          Broadcast a StorageListener.storeRequested(java.io.Serializable,java.io.Serializable,java.lang.Long,java.lang.Long,java.io.Serializable) event to my set of StorageListeners.
abstract  void clear()
          Remove all values previously stored.
abstract  void clear(Serializable key)
          Remove any value previously stored under the given key.
 void clearGroup(Serializable group)
          Remove any value previously stored under the given group.
abstract  boolean contains(Serializable key)
          Returns true if I have a value associated with the given key, false otherwise.
abstract  Serializable[] getKeysForGroup(Serializable group)
           
 long getStat(CacheStat stat)
           
 void registerRetrievalListener(RetrievalListener obs)
          Add the given RetrievalListener to my set of RetrievalListeners.
 void registerStorageListener(StorageListener obs)
          Add the given StorageListener to my set of StorageListeners.
abstract  Serializable retrieve(Serializable key)
          Obtain the value previously stored under the given key.
 boolean store(Serializable key, Serializable val, Long expiry, Long cost)
          Store the specified val under the specified key.
abstract  boolean store(Serializable key, Serializable val, Long expiry, Long cost, Serializable group)
          Store the specified val under the specified key and the specified group.
 void unregisterRetrievalListener(RetrievalListener obs)
          Remove the given RetrievalListener from my set of RetrievalListeners.
 void unregisterRetrievalListeners()
          Clear my set of RetrievalListeners.
 void unregisterStorageListener(StorageListener obs)
          Remove the given StorageListener from my set of StorageListeners.
 void unregisterStorageListeners()
          Clear my set of StorageListeners.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_storageListeners

protected ArrayList _storageListeners
My list of StorageListeners.


_retrievalListeners

protected ArrayList _retrievalListeners
My list of RetrievalListeners.

Constructor Detail

BaseCache

public BaseCache()
Method Detail

store

public abstract boolean store(Serializable key,
                              Serializable val,
                              Long expiry,
                              Long cost,
                              Serializable group)
Description copied from interface: Cache
Store the specified val under the specified key and the specified group.

Specified by:
store in interface Cache
Parameters:
key - the key used to later obtain the val from me, which MUST NOT be null.
val - the val to store, which MUST NOT be null.
expiry - the timestamp at which the given val becomes stale, or null.
cost - the implemenation dependent cost of generating the val, or null.
group - a meta-key which can be used to clear the object later
Returns:
true if the val was stored, false otherwise.

retrieve

public abstract Serializable retrieve(Serializable key)
Description copied from interface: Cache
Obtain the value previously stored under the given key.

Specified by:
retrieve in interface Cache
Parameters:
key - the key which MUST NOT be null.
Returns:
the previously stored value, or null.

getKeysForGroup

public abstract Serializable[] getKeysForGroup(Serializable group)
Specified by:
getKeysForGroup in interface Cache

contains

public abstract boolean contains(Serializable key)
Description copied from interface: Cache
Returns true if I have a value associated with the given key, false otherwise.

Specified by:
contains in interface Cache
Parameters:
key - the key which MUST NOT be null.
Returns:
true if I have a value associated with the given key, false otherwise.

clear

public abstract void clear(Serializable key)
Description copied from interface: Cache
Remove any value previously stored under the given key.

Specified by:
clear in interface Cache
Parameters:
key - the key which MUST NOT be null.

clear

public abstract void clear()
Description copied from interface: Cache
Remove all values previously stored.

Specified by:
clear in interface Cache

getStat

public long getStat(CacheStat stat)
             throws UnsupportedOperationException
Specified by:
getStat in interface Cache
Throws:
UnsupportedOperationException

clearGroup

public void clearGroup(Serializable group)
Description copied from interface: Cache
Remove any value previously stored under the given group.

Specified by:
clearGroup in interface Cache
Parameters:
group - the group which MUST NOT be null.

store

public boolean store(Serializable key,
                     Serializable val,
                     Long expiry,
                     Long cost)
Description copied from interface: Cache
Store the specified val under the specified key.

Specified by:
store in interface Cache
Parameters:
key - the key used to later obtain the val from me, which MUST NOT be null.
val - the val to store, which MUST NOT be null.
expiry - the timestamp at which the given val becomes stale, or null.
cost - the implemenation dependent cost of generating the val, or null.
Returns:
true if the val was stored, false otherwise.

registerStorageListener

public void registerStorageListener(StorageListener obs)
Add the given StorageListener to my set of StorageListeners.

Specified by:
registerStorageListener in interface Cache

unregisterStorageListener

public void unregisterStorageListener(StorageListener obs)
Remove the given StorageListener from my set of StorageListeners.

Specified by:
unregisterStorageListener in interface Cache

unregisterStorageListeners

public void unregisterStorageListeners()
Clear my set of StorageListeners.

Specified by:
unregisterStorageListeners in interface Cache

registerRetrievalListener

public void registerRetrievalListener(RetrievalListener obs)
Add the given RetrievalListener to my set of RetrievalListeners.

Specified by:
registerRetrievalListener in interface Cache

unregisterRetrievalListener

public void unregisterRetrievalListener(RetrievalListener obs)
Remove the given RetrievalListener from my set of RetrievalListeners.

Specified by:
unregisterRetrievalListener in interface Cache

unregisterRetrievalListeners

public void unregisterRetrievalListeners()
Clear my set of RetrievalListeners.

Specified by:
unregisterRetrievalListeners in interface Cache

broadcastStoreRequested

protected void broadcastStoreRequested(Serializable key,
                                       Serializable val,
                                       Long expiresAt,
                                       Long cost,
                                       Serializable group)
Broadcast a StorageListener.storeRequested(java.io.Serializable,java.io.Serializable,java.lang.Long,java.lang.Long,java.io.Serializable) event to my set of StorageListeners.

Parameters:
key - the cache key
val - the cache value
expiresAt - the expiration timestamp, or null
cost - the cost of the object, or null

broadcastStored

protected void broadcastStored(Serializable key,
                               Serializable val,
                               Long expiresAt,
                               Long cost,
                               Serializable group)
Broadcast a StorageListener.stored(java.io.Serializable,java.io.Serializable,java.lang.Long,java.lang.Long,java.io.Serializable) event to my set of StorageListeners.

Parameters:
key - the cache key
val - the cache value
expiresAt - the expiration timestamp, or null
cost - the cost of the object, or null

broadcastNotStored

protected void broadcastNotStored(Serializable key,
                                  Serializable val,
                                  Long expiresAt,
                                  Long cost,
                                  Serializable group)
Broadcast a StorageListener.notStored(java.io.Serializable,java.io.Serializable,java.lang.Long,java.lang.Long,java.io.Serializable) event to my set of StorageListeners.

Parameters:
key - the cache key
val - the cache value
expiresAt - the expiration timestamp, or null
cost - the cost of the object, or null

broadcastCleared

protected void broadcastCleared(Serializable key)
Broadcast a StorageListener.cleared(java.io.Serializable) event to my set of StorageListeners.

Parameters:
key - the cache key

broadcastCleared

protected void broadcastCleared()
Broadcast a StorageListener.cleared() event to my set of StorageListeners.


broadcastRetrieveRequested

protected void broadcastRetrieveRequested(Serializable key)
Broadcast a RetrievalListener.retrieveRequested(java.io.Serializable) event to my set of RetrievalListeners.

Parameters:
key - the cache key

broadcastRetrieved

protected void broadcastRetrieved(Serializable key)
Broadcast a RetrievalListener.retrieved(java.io.Serializable) event to my set of RetrievalListeners.

Parameters:
key - the cache key

broadcastNotRetrieved

protected void broadcastNotRetrieved(Serializable key)
Broadcast a RetrievalListener.notRetrieved(java.io.Serializable) event to my set of RetrievalListeners.

Parameters:
key - the cache key


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.