org.apache.cocoon.util
Interface SourceCache

All Known Implementing Classes:
SoftSourceCache

public interface SourceCache

A source cache caches Objects that are created from a source. It handles transparently rereading sources and recreation of objects if the source validity has expired or the object has been cleaned from the cache. For this, a reloader callback needs to be registered that actually does the recreation of the cached object.

Example:

 
   public void service(ServiceManager manager) {
      ...
      // obtain source cache on startup / service / initialize
      SourceCache cache = (SourceCache) manager.lookup(SourceCache.ROLE);
      // register reloader
      // with anonymous class handling the callback
      cache.register( new SourceReloader() { 
                 public Object reload(Source src, Object param) {
                     return refresh(src, (String) param[0], (Integer) param[1] );
                 });
   }
  
   // have callback method. Private is OK because its used from a anonymous
   // nested class.
   private CreatedObject refresh(Source src, String param1, Integer param2) {
      ...
   }

 
   public void foo() {
      ...
      // use cache
      CreatedObject foo = (CreatedObject) cache.getObject(resolver, key, uri, 
      ...                                                    Object[] { param1, new Integer(param2) });
   }
 
   public void dispose() {
      // release source cache on dispose
      manager.release(cache);
   }
 
 

Since:
2.1.4
Version:
CVS $Id: SourceCache.java 30941 2004-07-29 19:56:58Z vgritsenko $
Author:
Christian Haul

Field Summary
static String ROLE
           
 
Method Summary
 Object getObject(SourceResolver resolver, Object key, String uri, Object parameter)
          Retrieve an object from the cache.
 void register(SourceReloader reloader)
          Register a source reloader that will recreate cached objects.
 

Field Detail

ROLE

public static final String ROLE
Method Detail

register

public void register(SourceReloader reloader)
Register a source reloader that will recreate cached objects. Often, this will be done using an anonymous nested class.

Parameters:
reloader -

getObject

public Object getObject(SourceResolver resolver,
                        Object key,
                        String uri,
                        Object parameter)
                 throws MalformedURLException,
                        IOException
Retrieve an object from the cache. Transparently reloads and recreates objects using the registered source reloader if the objects identified by the key hasn't been cached or has been cleared from the cache, or source has changed.

Parameters:
resolver - A source resolver to use.
key - An object used as a key to the cached object.
uri - A string holding the URI.
parameter - Parameters to pass to the source reloader.
Returns:
Cached object.
Throws:
MalformedURLException
IOException


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