com.croftsoft.core.util.cache
Interface Cache

All Known Implementing Classes:
MemoryMapCache, SecureCache, SoftCache, WeakCache

public interface Cache

Stores the content and then returns an Id which may be used to read the content later, if still available.

Since:
1999-04-24
Version:
2003-06-07
See Also:
SoftCache
Author:
David Wallace Croft

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.
 

Method Detail

validate

Id validate(Id id,
            ContentAccessor contentAccessor)
            throws IOException
"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.

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

Id store(InputStream in)
         throws IOException
Stores the contents and returns an Id to be used for retrieval.

Reads the stream until completion and closes it before return.

Returns:
Returns an Id to be used for later retrieval. Returns null if the storage was unsuccessful.
Throws:
IOException

retrieve

InputStream retrieve(Id id)
                     throws IOException
Retrieves the content associated with this Id.

Parameters:
id - Returns the content associated with this id or its equivalent.
Returns:
May return null.
Throws:
IOException

isAvailable

boolean isAvailable(Id id)
Returns false if the content is no longer available.

Parameters:
id - An Id object to be used to retrieve the content.

CroftSoft Javadoc

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