|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.cocoon.components.source.impl.CachingSourceFactory
This class implements a proxy like source caches the contents of the source it wraps. This implementation can cache the content either for a given period of time or until an external event invalidates the cached response.
When using the timeout approach you have a choice between two separate revalidation strategies:
The URL needs to contain the URL of the cached source, an expiration
period in seconds, and optionally a cache key:
cached:http://www.apache.org/[?cocoon:cache-expires=60][&cocoon:cache-name=main][&cocoon:cache-fail=true]
.
The above examples shows 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 cache-fail
argument lets subsequent syncronous requests, that have to be refreshed, fail, in the case
that the wrapped source can't be reached. The default value for cache-fail
is true
.
This factory creates either instances of CachingSource
or TraversableCachingSource
depending on the whether the wrapped Source is an instance of TraversableSource.
If other types of sources should be supported, subclass this class and override the method
instantiateSource(String, String, Source, int, String, boolean)
.
In order to use the CachingSourceFactory in Cocoon, you have to set it up as Spring bean. For this purpose
you can use the abstract bean definition with the name
org.apache.excalibur.source.SourceFactory/caching::abstract
:
<bean name="org.apache.excalibur.source.SourceFactory/cached::abstract"
class="org.apache.cocoon.components.source.impl.CachingSourceFactory"
abstract="true">
<property name="cache" ref="org.apache.cocoon.caching.Cache"/>
<property name="sourceResolver" ref="org.apache.excalibur.source.SourceResolver"/>
<property name="serviceManager" ref="org.apache.avalon.framework.service.ServiceManager"/>
<property name="validityStrategy">
<bean class="org.apache.cocoon.components.source.impl.ExpiresCachingSourceValidityStrategy"/>
</property>
</bean>
It is also possible to override dependencies partially there.
Field Summary | |
protected boolean |
async
Asynchronous ? |
protected org.apache.cocoon.caching.Cache |
cache
The cache |
protected int |
defaultExpires
|
protected SourceRefresher |
refresher
The refresher |
protected SourceResolver |
resolver
The SourceResolver |
protected String |
scheme
Protocol prefix / factory name |
protected ServiceManager |
serviceManager
The Cocoon service manager |
protected CachingSourceValidityStrategy |
validityStrategy
Validity strategy implementation |
Fields inherited from interface org.apache.excalibur.source.SourceFactory |
ROLE |
Constructor Summary | |
CachingSourceFactory()
|
Method Summary | |
String |
absolutize(String baseURI,
String location)
|
protected CachingSource |
createCachingSource(String uri,
String wrappedUri,
Source wrappedSource,
int expires,
String cacheName,
boolean fail)
Actually creates a new CachingSource. |
Source |
getSource(String location,
Map parameters)
Get a Source object. |
protected CachingSource |
instantiateSource(String uri,
String wrappedUri,
Source wrappedSource,
int expires,
String cacheName,
boolean fail)
|
void |
release(Source source)
Release a Source object. |
void |
setAsync(boolean async)
Optional property whether the source is asyncronous. |
void |
setBeanName(String beanName)
|
void |
setCache(org.apache.cocoon.caching.Cache cache)
Mandatory dependency on an implementation of Cache . |
void |
setDefaultExpires(int expires)
Optional property the default expiry time in seconds. |
void |
setServiceManager(ServiceManager serviceManager)
Mandatory dependency on an implementation of ServiceManager . |
void |
setSourceRefresher(SourceRefresher refresher)
Optional dependency on an implementation of SourceRefresher . |
void |
setSourceResolver(SourceResolver resolver)
Mandatory dependency on an implementation of SourceResolver . |
void |
setValidityStrategy(CachingSourceValidityStrategy validityStrategy)
Mandatory dependency on an implementation of CachingSourceValidityStrategy . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected String scheme
protected boolean async
protected int defaultExpires
protected CachingSourceValidityStrategy validityStrategy
protected org.apache.cocoon.caching.Cache cache
protected SourceRefresher refresher
protected ServiceManager serviceManager
protected SourceResolver resolver
SourceResolver
Constructor Detail |
public CachingSourceFactory()
Method Detail |
public Source getSource(String location, Map parameters) throws IOException
Source
object.
getSource
in interface SourceFactory
parameters
- This is optional.
IOException
protected CachingSource createCachingSource(String uri, String wrappedUri, Source wrappedSource, int expires, String cacheName, boolean fail) throws SourceException
SourceException
protected CachingSource instantiateSource(String uri, String wrappedUri, Source wrappedSource, int expires, String cacheName, boolean fail)
public void release(Source source)
Source
object.
release
in interface SourceFactory
public String absolutize(String baseURI, String location)
absolutize
in interface URIAbsolutizer
URIAbsolutizer.absolutize(java.lang.String, java.lang.String)
public void setCache(org.apache.cocoon.caching.Cache cache)
Cache
.
public void setValidityStrategy(CachingSourceValidityStrategy validityStrategy)
CachingSourceValidityStrategy
.
public void setServiceManager(ServiceManager serviceManager)
ServiceManager
.
public void setSourceResolver(SourceResolver resolver)
SourceResolver
.
public void setSourceRefresher(SourceRefresher refresher)
SourceRefresher
.
public void setAsync(boolean async)
false
.
public void setDefaultExpires(int expires)
-1
which means that is valid forever.
public void setBeanName(String beanName)
setBeanName
in interface BeanNameAware
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |