|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.croftsoft.core.util.cache.SoftCache
public class SoftCache
A Cache implementation that dumps its content when memory is low.
Backed by a WeakCache. Note that the content will not be dumped if its Id remains strongly reachable.
WeakCache,
SoftReference| Constructor Summary | |
|---|---|
SoftCache()
|
|
| Method Summary | |
|---|---|
void |
clearQueue()
|
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 |
|---|
public SoftCache()
| Method Detail |
|---|
public Id validate(Id id,
ContentAccessor contentAccessor)
throws IOException
Cache
validate in interface Cacheid - 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.
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.
IOException
public Id store(InputStream in)
throws IOException
CacheReads the stream until completion and closes it before return.
store in interface CacheIOException
public InputStream retrieve(Id id)
throws IOException
Cache
retrieve in interface Cacheid - Returns the content associated with this id or its equivalent.
IOExceptionpublic boolean isAvailable(Id id)
Cache
isAvailable in interface Cacheid - An Id object to be used to retrieve the content.public void clearQueue()
|
CroftSoft Javadoc | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||