freemarker.template.cache
Class BaseCachingStrategy

java.lang.Object
  extended by freemarker.template.cache.BaseCachingStrategy
All Implemented Interfaces:
Cache, CachingStrategy, Updateable
Direct Known Subclasses:
LoadAdHocCachingStrategy, LoadOnDemandCachingStrategy, LoDWithRefreshCachingStrategy, NullCachingStrategy, PreloadCachingStrategy

public abstract class BaseCachingStrategy
extends java.lang.Object
implements CachingStrategy

Base class for implementing common elements of the caching strategies included with FM-Classic.

Version:
$Id: BaseCachingStrategy.java 1101 2013-04-01 04:17:32Z run2000 $
Author:
Nicholas Cull

Field Summary
protected  CacheEventAdapter eventHandler
          A proxy object for firing cache events to any listening event handlers.
protected  CacheRetriever retriever
          An object from which a caching strategy can retrieve templates.
 
Constructor Summary
BaseCachingStrategy()
          Default constructor.
BaseCachingStrategy(CacheRetriever retriever)
          Creates new BaseCachingStrategy with a cache retriever.
 
Method Summary
 void addCacheListener(CacheListener listener)
          Registers a CacheListener for this Cache.
protected  boolean connectionOk()
          Determines whether our data source is still available.
 CacheListener[] getCacheListeners()
          Returns all the CacheListeners registered with this strategy.
 CacheRetriever getCacheRetriever()
          Returns the current retriever.
 void removeCacheListener(CacheListener listener)
          Unregisters a CacheListener for this Cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface freemarker.template.cache.CachingStrategy
clearCache, getDefaultTemplateType, getDelay, getMaximumAge, startAutoUpdate
 
Methods inherited from interface freemarker.template.cache.Updateable
update, update, update
 
Methods inherited from interface freemarker.template.cache.Cache
getItem, getItem, listCachedFiles, stopAutoUpdate
 

Field Detail

eventHandler

protected CacheEventAdapter eventHandler
A proxy object for firing cache events to any listening event handlers.


retriever

protected CacheRetriever retriever
An object from which a caching strategy can retrieve templates. Typically proxies for a file system.

Constructor Detail

BaseCachingStrategy

public BaseCachingStrategy()
Default constructor.


BaseCachingStrategy

public BaseCachingStrategy(CacheRetriever retriever)
Creates new BaseCachingStrategy with a cache retriever.

Parameters:
retriever - the retriever to use to pull items from the data store
Method Detail

getCacheRetriever

public CacheRetriever getCacheRetriever()
Returns the current retriever.

Specified by:
getCacheRetriever in interface CachingStrategy
Returns:
the current cache retriever

addCacheListener

public void addCacheListener(CacheListener listener)
Registers a CacheListener for this Cache.

Specified by:
addCacheListener in interface Cache
Parameters:
listener - the CacheListener to be registered.

getCacheListeners

public CacheListener[] getCacheListeners()
Returns all the CacheListeners registered with this strategy.

Specified by:
getCacheListeners in interface Cache
Returns:
an array of CacheListeners that have been registered.

removeCacheListener

public void removeCacheListener(CacheListener listener)
Unregisters a CacheListener for this Cache.

Specified by:
removeCacheListener in interface Cache
Parameters:
listener - the CacheListener to be unregistered.

connectionOk

protected boolean connectionOk()
Determines whether our data source is still available. If not, fires a cache event and stops auto-updates, since this is a fatal condition for the cache to encounter.

Returns:
true if the data source is ok, otherwise false