org.apache.cocoon.pipeline.caching
Class AbstractCache

java.lang.Object
  extended by org.apache.cocoon.pipeline.caching.AbstractCache
All Implemented Interfaces:
Cache
Direct Known Subclasses:
SimpleCache

public abstract class AbstractCache
extends Object
implements Cache

An abstract implementation of the Cache interface.

It handles the validity check for retrieving CacheValues but relies on child classes for actually accessing the underlying stores.


Constructor Summary
AbstractCache()
           
 
Method Summary
 void clear()
          Removes all data coneined in this Cache
protected abstract  void doClear()
          Actually clears the underlying storage.
protected abstract  boolean doRemove(CacheKey cacheKey)
          Actually removes cached data from underlying storage.
 CacheValue get(CacheKey cacheKey)
          Retrieves the CacheValue previously stored using the given cacheKey.
 CacheValue get(CacheKey cacheKey, boolean includeInvalid)
          Retrieves the CacheValue previously stored using the given cacheKey.
protected  boolean isValid(CacheKey cacheKey, CacheValue cacheValue)
          Determines if the given cacheValue is valid according to the given cacheKey.
 Set<CacheKey> keySet()
          Returns Set of CacheKey contained in this Cache
 void put(CacheKey cacheKey, CacheValue cacheValue)
          Stores the given cacheValue at the given cacheKey.
 boolean remove(CacheKey cacheKey)
          Removes that CacheKey from this Cache.
protected abstract  CacheValue retrieve(CacheKey cacheKey)
          Actually retrieves the CacheValue from the underlying storage.
protected abstract  Set<CacheKey> retrieveKeySet()
          Actually retrieves the Set for CacheKey from underlying storage.
protected abstract  void store(CacheKey cacheKey, CacheValue cacheValue)
          Actually stores the given cacheValue at the given cacheKey in the underlying storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractCache

public AbstractCache()
Method Detail

get

public final CacheValue get(CacheKey cacheKey)
Retrieves the CacheValue previously stored using the given cacheKey.
If the cacheKey is not stored in this Cache this method will return null.

Furthermore the Cache will check if the stored CacheValue is still valid (using the CacheValue.isValid(CacheKey) method). If the CacheValue is considered to be invalid this method will return null as well (indicating that no valid CacheValue is available).

To retrieve CacheValues even if they are invalid, use the Cache.get(CacheKey, boolean) method.

Specified by:
get in interface Cache
Parameters:
cacheKey - The CacheKey defining which CacheValue to retrieve.
Returns:
The previously stored CacheValue or null if no or no valid CacheValue is stored at the given cacheValue.
See Also:
Cache.get(org.apache.cocoon.pipeline.caching.CacheKey)

get

public final CacheValue get(CacheKey cacheKey,
                            boolean includeInvalid)
Retrieves the CacheValue previously stored using the given cacheKey.
If the cacheKey is not stored in this Cache this method will return null.

This method will omit the check for validity if includeInvalid is true (i.e. the returned CacheValue might be invalid in this case).

Specified by:
get in interface Cache
Parameters:
cacheKey - The CacheKey defining which CacheValue to retrieve.
includeInvalid - Defines whether invalid CacheValue should be returned or not. Using true will also return invalid CacheValue. Using false will yield the same results as Cache.get(CacheKey).
Returns:
The previously stored CacheValue or null if and only if no CacheValue is stored at the given cacheValue.
See Also:
Cache.get(org.apache.cocoon.pipeline.caching.CacheKey, boolean)

put

public final void put(CacheKey cacheKey,
                      CacheValue cacheValue)
Stores the given cacheValue at the given cacheKey.

If this cache already contains the given cacheKey it will be replaced.
If two CacheKeys represent the same data is ultimately depending on the implementation, but usually relies on the equals an/or hashcode methods.

Specified by:
put in interface Cache
Parameters:
cacheKey - The CacheKey to be used for storing.
cacheValue - The CacheValue to be stored.
See Also:
Cache.put(org.apache.cocoon.pipeline.caching.CacheKey, org.apache.cocoon.pipeline.caching.CacheValue)

clear

public void clear()
Removes all data coneined in this Cache

Specified by:
clear in interface Cache
See Also:
Cache.clear()

remove

public boolean remove(CacheKey cacheKey)
Removes that CacheKey from this Cache.

Specified by:
remove in interface Cache
See Also:
Cache.remove(org.apache.cocoon.pipeline.caching.CacheKey)

keySet

public Set<CacheKey> keySet()
Returns Set of CacheKey contained in this Cache

Specified by:
keySet in interface Cache
Returns:
a set CacheKey contained in this Cache
See Also:
Cache.keySet()

isValid

protected boolean isValid(CacheKey cacheKey,
                          CacheValue cacheValue)
Determines if the given cacheValue is valid according to the given cacheKey.

This method returns true if and only if the given cacheValue is not null and calling CacheValue.isValid(CacheKey) with the given cacheKey returns true.

Parameters:
cacheKey - The CacheKey to be used for checking the cacheValue's validity.
cacheValue - The CacheValue to check for validity.
Returns:
true if the given cacheValue is not null and valid for the given cacheKey.

retrieve

protected abstract CacheValue retrieve(CacheKey cacheKey)
Actually retrieves the CacheValue from the underlying storage.
This method must return the previously stored value - even if it is not valid anymore.

Parameters:
cacheKey - The CacheKey to be used for retrieval.
Returns:
The previously stored CacheValue or null if no CacheValue is stored at the given cacheKey.

store

protected abstract void store(CacheKey cacheKey,
                              CacheValue cacheValue)
Actually stores the given cacheValue at the given cacheKey in the underlying storage.

This method is to replace any previously stored CacheValue (if any).

Parameters:
cacheKey - The CacheKey to be used for storing.
cacheValue - The CacheValue to be stored.

doClear

protected abstract void doClear()
Actually clears the underlying storage.


doRemove

protected abstract boolean doRemove(CacheKey cacheKey)
Actually removes cached data from underlying storage.

Parameters:
cacheKey - The CacheKey to be removed.

retrieveKeySet

protected abstract Set<CacheKey> retrieveKeySet()
Actually retrieves the Set for CacheKey from underlying storage.

Returns:
The Set of CacheKey of containded data.


Copyright © 2008-2012 The Apache Software Foundation. All Rights Reserved.