freemarker.template.cache
Class LoadOnDemandCachingStrategy

java.lang.Object
  |
  +--freemarker.template.cache.BaseCachingStrategy
        |
        +--freemarker.template.cache.LoadOnDemandCachingStrategy
All Implemented Interfaces:
Cache, CachingStrategy, Updateable

public final class LoadOnDemandCachingStrategy
extends BaseCachingStrategy

Implements a load-on-demand caching strategy.

Version:
$Id: LoadOnDemandCachingStrategy.java,v 1.18 2003/11/27 08:03:46 run2000 Exp $
Author:
Nicholas Cull

Fields inherited from class freemarker.template.cache.BaseCachingStrategy
eventHandler, retriever
 
Constructor Summary
LoadOnDemandCachingStrategy()
          Creates new LoadOnDemandCachingStrategy.
 
Method Summary
 void clearCache()
          Clears all the elements in the cache.
 long getDelay()
          Returns the interval between two cache updates.
 Cacheable getItem(java.lang.String name)
          Retrieves an item from the cache, according to the loading policy implemented.
 Cacheable getItem(java.lang.String name, java.lang.String type)
          Retrieves an item from the cache, according to the loading policy implemented.
 int getMaximumAge()
          Retrieves the maximum age a cache item can be before it is evicted from the cache.
 java.util.Iterator listCachedFiles()
          Retrieves a list of objects currently in the cache.
 void setDefaultTemplate(java.lang.String aTemplate)
          Sets the default template to use when retrieving.
 void setDelay(long delay)
          Sets the interval between two cache updates.
 void setMaximumAge(int age)
          Sets the maximum age a cache item can be before it is evicted from the cache.
 void startAutoUpdate()
          Begins automatic updates of the cache.
 void stopAutoUpdate()
          Stops automatically updating the cache.
 java.lang.String toString()
          Returns a string representation of the object.
 void update()
          Asks for a "blank" update.
 void update(java.lang.String name)
          Asks for the named object to be updated.
 void update(java.lang.String name, java.lang.String type)
          Asks for the named object to be updated.
 
Methods inherited from class freemarker.template.cache.BaseCachingStrategy
addCacheListener, connectionOk, getCacheListeners, getCacheRetriever, removeCacheListener, setCacheRetriever, setEventHandler
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LoadOnDemandCachingStrategy

public LoadOnDemandCachingStrategy()
Creates new LoadOnDemandCachingStrategy.
Method Detail

setDelay

public void setDelay(long delay)
Sets the interval between two cache updates. This is meaningful only if the cache policy is a load-on-demand or preload type.
Parameters:
delay - the number of seconds between cache updates

getDelay

public long getDelay()
Returns the interval between two cache updates. This is meaningful only if the cache policy is a load-on-demand or preload type.
Returns:
the number of seconds between cache updates

setMaximumAge

public void setMaximumAge(int age)
Sets the maximum age a cache item can be before it is evicted from the cache. The age is determined as the number of cache updates since the item was last accessed. This is meaningful only if the cache policy is a load-on-demand type.
Parameters:
age - the maximum age before an item is evicted from the cache

getMaximumAge

public int getMaximumAge()
Retrieves the maximum age a cache item can be before it is evicted from the cache. The age is determined as the number of cache updates since the item was last accessed. This is meaningful only if the cache policy is a load-on-demand type.
Returns:
the maximum age before an item is evicted from the cache

getItem

public Cacheable getItem(java.lang.String name)
Retrieves an item from the cache, according to the loading policy implemented.
Parameters:
name - the name of the item to retrieve
Returns:
the corresponding Cacheable object, or null if not found or an error has occurred

getItem

public Cacheable getItem(java.lang.String name,
                         java.lang.String type)
Retrieves an item from the cache, according to the loading policy implemented.
Parameters:
name - the name of the item to retrieve
type - the type of item to be retrieved
Returns:
the corresponding Cacheable object, or null if not found or an error has occurred

listCachedFiles

public java.util.Iterator listCachedFiles()
Retrieves a list of objects currently in the cache.
Returns:
an iterator that can recurse over the cached objects. May return null if there are no items in the cache, or the strategy does not implement a cache.

update

public void update()
            throws java.lang.InterruptedException
Asks for a "blank" update. It is up to the implementation to determine what has to be updated.
Following copied from interface: freemarker.template.cache.Updateable
Throws:
java.lang.InterruptedException - The current thread was interrupted during the update. Callers should either throw the exception back up the call stack, or set the interrupted status by using the Thread.currentThread().interrupt() method.

update

public void update(java.lang.String name)
Asks for the named object to be updated.
Parameters:
name - the name of the object to update

update

public void update(java.lang.String name,
                   java.lang.String type)
Asks for the named object to be updated.
Parameters:
name - the name of the object to update
type - the type of the object to update

stopAutoUpdate

public void stopAutoUpdate()
Stops automatically updating the cache.

startAutoUpdate

public void startAutoUpdate()
Begins automatic updates of the cache.

clearCache

public void clearCache()
Clears all the elements in the cache.

setDefaultTemplate

public void setDefaultTemplate(java.lang.String aTemplate)
Sets the default template to use when retrieving.
Following copied from interface: freemarker.template.cache.CachingStrategy
Parameters:
template - the type of template to be used by default when retrieving objects from the repository

toString

public java.lang.String toString()
Returns a string representation of the object.
Overrides:
toString in class java.lang.Object
Returns:
a String representation of the object