org.apache.cocoon.components.source.impl
Class CachingSourceFactory

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.cocoon.components.source.impl.CachingSourceFactory
All Implemented Interfaces:
Component, Configurable, Disposable, LogEnabled, Serviceable, SourceFactory, ThreadSafe, URIAbsolutizer

public final class CachingSourceFactory
extends AbstractLogEnabled
implements SourceFactory, URIAbsolutizer, Serviceable, Configurable, Disposable, ThreadSafe

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.

1) Synchronously. This means that the cached contents are checked for validity and thrown out on the current thread.
2) Asynchronously. A cronjob is scheduled to invalidate and update the cached response in the backgound.

Protocol syntax

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].

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.

This factory creates either instances of CachingSource or TraversableCachingSource depending on the whether the wrapped Source is an instance of TraversableSource.

Parameters

cache-role (String) Role of component used as cache. opt String Cache.ROLE
refresher-role (String) Role of component used for refreshing sources. opt String Refresher.ROLE
async (boolean) Indicated if the cached source should be refreshed asynchronously. opt String false
default-expires (int) Default expiration value for if it is not specified on the Source itself. opt String -1

Since:
2.1.1
Version:
CVS $Id: CachingSourceFactory.java 30941 2004-07-29 19:56:58Z vgritsenko $

Field Summary
static String ASYNC_PARAM
           
protected  Cache cache
          The cache
static String CACHE_ROLE_PARAM
           
static String DEFAULT_EXPIRES_PARAM
           
static String FAILSAFE_PARAM
           
protected  ServiceManager manager
          The ServiceManager
protected  Refresher refresher
          The refresher
static String REFRESHER_ROLE_PARAM
           
protected  SourceResolver resolver
          The SourceResolver
 
Fields inherited from interface org.apache.excalibur.source.SourceFactory
ROLE
 
Constructor Summary
CachingSourceFactory()
           
 
Method Summary
 String absolutize(String baseURI, String location)
           
 void configure(Configuration configuration)
           
 void dispose()
           
 Source getSource(String location, Map parameters)
          Get a Source object.
static CachingSource newCachingSource(Source wrappedSource, String scheme, String uri, int expires, String cacheName, boolean async, Cache cache, Logger logger, ServiceManager manager)
          Factory method for creating a new CachingSource.
 void release(Source source)
          Release a Source object.
 void service(ServiceManager manager)
           
 
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

ASYNC_PARAM

public static final String ASYNC_PARAM
See Also:
Constant Field Values

FAILSAFE_PARAM

public static final String FAILSAFE_PARAM
See Also:
Constant Field Values

CACHE_ROLE_PARAM

public static final String CACHE_ROLE_PARAM
See Also:
Constant Field Values

REFRESHER_ROLE_PARAM

public static final String REFRESHER_ROLE_PARAM
See Also:
Constant Field Values

DEFAULT_EXPIRES_PARAM

public static final String DEFAULT_EXPIRES_PARAM
See Also:
Constant Field Values

manager

protected ServiceManager manager
The ServiceManager


resolver

protected SourceResolver resolver
The SourceResolver


refresher

protected Refresher refresher
The refresher


cache

protected Cache cache
The cache

Constructor Detail

CachingSourceFactory

public CachingSourceFactory()
Method Detail

service

public void service(ServiceManager manager)
Specified by:
service in interface Serviceable

configure

public void configure(Configuration configuration)
               throws ConfigurationException
Specified by:
configure in interface Configurable
Throws:
ConfigurationException

dispose

public void dispose()
Specified by:
dispose in interface Disposable

getSource

public Source getSource(String location,
                        Map parameters)
                 throws MalformedURLException,
                        IOException
Get a Source object.

Specified by:
getSource in interface SourceFactory
Parameters:
parameters - This is optional.
Throws:
MalformedURLException
IOException

newCachingSource

public static CachingSource newCachingSource(Source wrappedSource,
                                             String scheme,
                                             String uri,
                                             int expires,
                                             String cacheName,
                                             boolean async,
                                             Cache cache,
                                             Logger logger,
                                             ServiceManager manager)
                                      throws SourceException
Factory method for creating a new CachingSource.

Throws:
SourceException

release

public void release(Source source)
Release a Source object.

Specified by:
release in interface SourceFactory

absolutize

public String absolutize(String baseURI,
                         String location)
Specified by:
absolutize in interface URIAbsolutizer


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.