| org.apache.cocoon.components.source.impl.CachingSource
All known Subclasses: org.apache.cocoon.components.source.impl.TraversableCachingSource,
CachingSource | public class CachingSource extends AbstractLogEnabled implements Serviceable,Initializable,XMLizable,Source(Code) | | This class implements a proxy like source that uses another source
to get the content. This implementation can cache the content for
a given period of time.
Syntax for Protocol
cached:http://www.apache.org/[?cocoon:cache-expires=60&cocoon:cache-name=main]
The above examples show how the real source http://www.apache.org
is wrapped and the cached contents is used for 60 seconds.
The second querystring parameter instructs that the cache key be extended with the string
main . This allows the use of multiple cache entries for the same source.
The value of the expires parameter holds some additional semantics.
Specifying -1 will yield the cached response to be considered valid
always. Value 0 can be used to achieve the exact opposite. That is to say,
the cached contents will be thrown out and updated immediately and unconditionally.
version: $Id: CachingSource.java 485495 2006-12-11 04:44:23Z crossley $ |
Inner Class :protected static class SourceMeta implements Serializable | |
Constructor Summary | |
public | CachingSource(String protocol, String uri, String sourceUri, Source source, int expires, String cacheName, boolean async, boolean eventAware) Construct a new object. |
Method Summary | |
public void | dispose() Cleanup. | public boolean | exists() | protected byte[] | getBinaryResponse() Initialize the cached response with meta and binary contents. | protected String | getCacheKey() Return the used key. | protected SourceValidity[] | getCacheValidities() | public long | getContentLength() Get the content length of the source or -1 if it
is not possible to determine the length. | protected long | getExpiration() | public InputStream | getInputStream() Return an InputStream object to read from the source. | public long | getLastModified() Get the last modification date. | public String | getMimeType() The mime-type of the content described by this object. | protected SourceMeta | getResponseMeta() Initialize the cached response with meta info. | public String | getScheme() Return the protocol identifier. | protected String | getSourceURI() Return the uri of the cached source. | public String | getURI() | public SourceValidity | getValidity() Get the Validity object. | protected byte[] | getXMLResponse() Initialize the cached response with meta, binary, and XML contents. | public void | initialize() Initialize the Source. | protected byte[] | readBinaryResponse(Source source) Read binary content from source. | protected SourceMeta | readMeta(Source source) Read meta data from source. | protected byte[] | readXMLResponse(Source source, byte[] binary, ServiceManager manager) Read XML content from source. | public void | refresh() Refresh this object and update the last modified date
and content length. | public void | service(ServiceManager manager) Set the ServiceManager. | public void | toSAX(ContentHandler contentHandler) Generates SAX events representing the object's state. |
CACHE_EXPIRES_PARAM | final public static String CACHE_EXPIRES_PARAM(Code) | | |
CACHE_NAME_PARAM | final public static String CACHE_NAME_PARAM(Code) | | |
async | final protected boolean async(Code) | | asynchronic refresh strategy ?
|
cacheName | final protected String cacheName(Code) | | cache key extension
|
eventAware | final protected boolean eventAware(Code) | | |
expires | final protected int expires(Code) | | number of seconds before cached object becomes invalid
|
manager | protected ServiceManager manager(Code) | | The ServiceManager
|
protocol | final protected String protocol(Code) | | The used protocol
|
source | protected Source source(Code) | | The source object for the real content
|
sourceUri | final protected String sourceUri(Code) | | The full URI string of the underlying source
|
CachingSource | public CachingSource(String protocol, String uri, String sourceUri, Source source, int expires, String cacheName, boolean async, boolean eventAware)(Code) | | Construct a new object.
|
dispose | public void dispose()(Code) | | Cleanup.
|
exists | public boolean exists()(Code) | | See Also: org.apache.excalibur.source.Source.exists |
getBinaryResponse | protected byte[] getBinaryResponse() throws IOException(Code) | | Initialize the cached response with meta and binary contents.
throws: IOException - if an the binary response could not be initialized |
getCacheKey | protected String getCacheKey()(Code) | | Return the used key.
|
getCacheValidities | protected SourceValidity[] getCacheValidities()(Code) | | |
getContentLength | public long getContentLength()(Code) | | Get the content length of the source or -1 if it
is not possible to determine the length.
|
getExpiration | protected long getExpiration()(Code) | | Expires (in milli-seconds)
|
getInputStream | public InputStream getInputStream() throws IOException, SourceException(Code) | | Return an InputStream object to read from the source.
|
getLastModified | public long getLastModified()(Code) | | Get the last modification date.
The last modification in milliseconds since January 1, 1970 GMTor 0 if it is unknown |
getMimeType | public String getMimeType()(Code) | | The mime-type of the content described by this object.
If the source is not able to determine the mime-type by itself
this can be null.
|
getResponseMeta | protected SourceMeta getResponseMeta() throws IOException(Code) | | Initialize the cached response with meta info.
throws: IOException - if an the binary response could not be initialized |
getScheme | public String getScheme()(Code) | | Return the protocol identifier.
|
getSourceURI | protected String getSourceURI()(Code) | | Return the uri of the cached source.
|
getURI | public String getURI()(Code) | | Return the unique identifer for this source
|
getValidity | public SourceValidity getValidity()(Code) | | Get the Validity object. This can either wrap the last modification
date or the expires information or...
If it is currently not possible to calculate such an information
null is returned.
|
initialize | public void initialize() throws Exception(Code) | | Initialize the Source.
|
readBinaryResponse | protected byte[] readBinaryResponse(Source source) throws IOException, SourceNotFoundException(Code) | | Read binary content from source.
content from source throws: IOException - throws: SourceNotFoundException - |
readMeta | protected SourceMeta readMeta(Source source) throws SourceException(Code) | | Read meta data from source.
|
refresh | public void refresh()(Code) | | Refresh this object and update the last modified date
and content length.
This method will try to refresh the cached meta data
and content only if cached content is expired.
|
service | public void service(ServiceManager manager) throws ServiceException(Code) | | Set the ServiceManager.
|
|
|