|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.avalon.framework.logger.AbstractLogEnabled org.apache.cocoon.components.source.impl.CachingSource
public class CachingSource
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.
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.
Nested Class Summary | |
---|---|
protected static class |
CachingSource.SourceMeta
Data holder for caching Source meta info. |
Field Summary | |
---|---|
protected boolean |
async
asynchronic refresh strategy ? |
protected Cache |
cache
The current cache |
static String |
CACHE_EXPIRES_PARAM
|
static String |
CACHE_NAME_PARAM
|
protected IdentifierCacheKey |
cacheKey
The key used in the store |
protected String |
cacheName
cache key extension |
protected boolean |
eventAware
|
protected int |
expires
number of seconds before cached object becomes invalid |
protected ServiceManager |
manager
The ServiceManager |
protected String |
protocol
The used protocol |
protected Source |
source
The source object for the real content |
protected String |
sourceUri
The full URI string of the underlying source |
protected String |
uri
The full URI string |
Constructor Summary | |
---|---|
CachingSource(String protocol,
String uri,
String sourceUri,
Source source,
int expires,
String cacheName,
boolean async,
boolean eventAware)
Construct a new object. |
Method Summary | |
---|---|
void |
dispose()
Cleanup. |
boolean |
exists()
|
protected byte[] |
getBinaryResponse()
Initialize the cached response with meta and binary contents. |
protected String |
getCacheKey()
Return the used key. |
protected SourceValidity[] |
getCacheValidities()
|
long |
getContentLength()
Get the content length of the source or -1 if it is not possible to determine the length. |
protected long |
getExpiration()
Expires (in milli-seconds) |
InputStream |
getInputStream()
Return an InputStream object to read from the source. |
long |
getLastModified()
Get the last modification date. |
String |
getMimeType()
The mime-type of the content described by this object. |
protected CachingSource.SourceMeta |
getResponseMeta()
Initialize the cached response with meta info. |
String |
getScheme()
Return the protocol identifier. |
protected String |
getSourceURI()
Return the uri of the cached source. |
String |
getURI()
Return the unique identifer for this source |
SourceValidity |
getValidity()
Get the Validity object. |
protected byte[] |
getXMLResponse()
Initialize the cached response with meta, binary, and XML contents. |
void |
initialize()
Initialize the Source. |
protected byte[] |
readBinaryResponse(Source source)
Read binary content from source. |
protected CachingSource.SourceMeta |
readMeta(Source source)
Read meta data from source. |
protected byte[] |
readXMLResponse(Source source,
byte[] binary,
ServiceManager manager)
Read XML content from source. |
void |
refresh()
Refresh this object and update the last modified date and content length. |
void |
service(ServiceManager manager)
Set the ServiceManager. |
void |
toSAX(ContentHandler contentHandler)
Generates SAX events representing the object's state. |
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled |
---|
enableLogging, getLogger, setupLogger, setupLogger, setupLogger |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String CACHE_EXPIRES_PARAM
public static final String CACHE_NAME_PARAM
protected final String protocol
protected final String uri
protected final String sourceUri
protected Source source
protected ServiceManager manager
protected Cache cache
protected final IdentifierCacheKey cacheKey
protected final int expires
protected final String cacheName
protected final boolean async
protected final boolean eventAware
Constructor Detail |
---|
public CachingSource(String protocol, String uri, String sourceUri, Source source, int expires, String cacheName, boolean async, boolean eventAware)
Method Detail |
---|
public void service(ServiceManager manager) throws ServiceException
service
in interface Serviceable
ServiceException
public void initialize() throws Exception
initialize
in interface Initializable
Exception
public void dispose()
protected CachingSource.SourceMeta getResponseMeta() throws IOException
IOException
- if an the binary response could not be initializedprotected byte[] getBinaryResponse() throws IOException
IOException
- if an the binary response could not be initializedprotected byte[] getXMLResponse() throws SAXException, IOException, CascadingIOException
SAXException
- if something happened during xml processing
IOException
- if an IO level error occured
CascadingIOException
- wraps all other exception typespublic String getScheme()
getScheme
in interface Source
public long getContentLength()
getContentLength
in interface Source
public long getLastModified()
getLastModified
in interface Source
public String getMimeType()
getMimeType
in interface Source
public InputStream getInputStream() throws IOException, SourceException
InputStream
object to read from the source.
getInputStream
in interface Source
IOException
SourceException
public String getURI()
getURI
in interface Source
public boolean exists()
exists
in interface Source
Source.exists()
public SourceValidity getValidity()
null
is returned.
getValidity
in interface Source
public void refresh()
refresh
in interface Source
public void toSAX(ContentHandler contentHandler) throws SAXException
toSAX
in interface XMLizable
SAXException
protected String getSourceURI()
protected String getCacheKey()
protected long getExpiration()
protected byte[] readXMLResponse(Source source, byte[] binary, ServiceManager manager) throws SAXException, IOException, CascadingIOException
SAXException
IOException
CascadingIOException
protected byte[] readBinaryResponse(Source source) throws IOException, SourceNotFoundException
IOException
SourceNotFoundException
protected CachingSource.SourceMeta readMeta(Source source) throws SourceException
SourceException
protected SourceValidity[] getCacheValidities()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |