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

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

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

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:

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 SourceRefresher.ROLE
async (boolean) Indicated if the cached source should be refreshed asynchronously. opt String false
event-aware (boolean) Whether to use event-based cache invalidation. 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:
$Id: CachingSourceFactory.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Field Summary
protected  Cache cache
          The cache
protected  ServiceManager manager
          The ServiceManager
protected  SourceRefresher refresher
          The refresher
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)
           
protected  CachingSource createCachingSource(String uri, String wrappedUri, Source wrappedSource, int expires, String cacheName)
          Actually creates a new CachingSource.
 void dispose()
           
protected  String getScheme()
           
 Source getSource(String location, Map parameters)
          Get a Source object.
protected  boolean isAsync()
           
 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

manager

protected ServiceManager manager
The ServiceManager


resolver

protected SourceResolver resolver
The SourceResolver


refresher

protected SourceRefresher 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

getScheme

protected String getScheme()

isAsync

protected boolean isAsync()

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

createCachingSource

protected CachingSource createCachingSource(String uri,
                                            String wrappedUri,
                                            Source wrappedSource,
                                            int expires,
                                            String cacheName)
                                     throws SourceException
Actually creates a new CachingSource. Can be overriden in subclasses

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-2010 The Apache Software Foundation. All Rights Reserved.