com.croftsoft.core.util.cache
Class MemoryMapCache

java.lang.Object
  extended by com.croftsoft.core.util.cache.MemoryMapCache
All Implemented Interfaces:
Cache
Direct Known Subclasses:
WeakCache

public class MemoryMapCache
extends Object
implements Cache

A Cache implementation that is backed by a memory Map.

The InputStreams are read and stored to the Map as byte arrays.

Version:
1999-04-24
See Also:
Cache, WeakHashMap, com.orbs.open.a.mpl.util.SoftHashMap
Author:
David Wallace Croft

Constructor Summary
MemoryMapCache(Map map)
           
 
Method Summary
 boolean isAvailable(Id id)
          Returns false if the content is no longer available.
 InputStream retrieve(Id id)
          Retrieves the content associated with this Id.
 Id store(InputStream in)
          Stores the contents and returns an Id to be used for retrieval.
 Id validate(Id id, ContentAccessor contentAccessor)
          "Validates" the content by confirming that identical content already exists in the cache; or, if otherwise necessary, storing a new copy of the content in the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryMapCache

public MemoryMapCache(Map map)
Method Detail

validate

public Id validate(Id id,
                   ContentAccessor contentAccessor)
            throws IOException
Description copied from interface: Cache
"Validates" the content by
  1. confirming that identical content already exists in the cache; or, if otherwise necessary,
  2. storing a new copy of the content in the cache.

Specified by:
validate in interface Cache
Parameters:
id - The content identifier passed to isAvailable() to determine if the content is already valid. The parameter may be any Id object that potentially matches via the equals() method.
contentAccessor - An object capable of making content accessible via an InputStream. For example, a ContentAccessor might retrieve content from a website via a URL, a database or file storage, a remote object such as another cache, or even dynamically generate the content upon demand. As yet another possibility, a ContentAccessor object may potentially attempt to access the content from several different sources sequentially until it is successful.
Returns:
Returns an Id object for the validated content which may be used later for retrieval.

If valid content was already available in the cache, the returned Id object will be the id parameter.

If valid content was not already available and the content could not be accessed and stored via the contentAccessor, the returned value will be null.

If valid content was not already available and the content could be accessed and stored via the contentAccessor, the returned value will be a new Id object with values that may or may not equal that of the id object parameter, depending on the actual content available via the contentAccessor.

Throws:
IOException

store

public Id store(InputStream in)
         throws IOException
Description copied from interface: Cache
Stores the contents and returns an Id to be used for retrieval.

Reads the stream until completion and closes it before return.

Specified by:
store in interface Cache
Returns:
Returns an Id to be used for later retrieval. Returns null if the storage was unsuccessful.
Throws:
IOException

retrieve

public InputStream retrieve(Id id)
                     throws IOException
Description copied from interface: Cache
Retrieves the content associated with this Id.

Specified by:
retrieve in interface Cache
Parameters:
id - Returns the content associated with this id or its equivalent.
Returns:
May return null.
Throws:
IOException

isAvailable

public boolean isAvailable(Id id)
Description copied from interface: Cache
Returns false if the content is no longer available.

Specified by:
isAvailable in interface Cache
Parameters:
id - An Id object to be used to retrieve the content.

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)