freemarker.template.cache
Interface CacheRetriever

All Known Implementing Classes:
FileRetriever, LocalizedFileRetriever

public interface CacheRetriever

Interface for retrieving objects to be stored in a Cache. This interface may be implemented in order to retrieve templates from a different data store, such as a relational database.

Version:
$Id: CacheRetriever.java,v 1.8 2003/11/03 03:33:32 run2000 Exp $

Method Summary
 boolean connectionOk()
          Corresponds to checkCacheDir for file-system implementations.
 boolean exists(java.lang.String location)
          Tests whether the object still exists in the template repository.
 java.lang.String getConnection()
          Gets the connection for this retriever.
 java.util.List getPreloadData()
          Returns a list of objects (Strings) to pre-load the cache with.
 long lastModified(java.lang.String location)
          Determines when the object in the template repository was last modified.
 Cacheable loadData(java.lang.String location, java.lang.String type)
          Retrieves data of the appropriate type to be stored in the cache.
 void setConnection(java.lang.String connection)
          Sets the connection for this retriever.
 

Method Detail

loadData

public Cacheable loadData(java.lang.String location,
                          java.lang.String type)
                   throws TemplateException
Retrieves data of the appropriate type to be stored in the cache.
Parameters:
location - the location of the data to be retrieved
type - the type of object to be returned
Returns:
a Cacheable object loaded from the data source
Throws:
TemplateException - the object could not be loaded

exists

public boolean exists(java.lang.String location)
Tests whether the object still exists in the template repository. This may be redundant. Instead, lastModified could throw an appropriate exception.
Parameters:
location - the location of the object to be tested
Returns:
true if the object still exists in the repository, otherwise false
See Also:
lastModified(java.lang.String)

lastModified

public long lastModified(java.lang.String location)
                  throws TemplateException

Determines when the object in the template repository was last modified.

Parameters:
location - the location of the object to be tested
Returns:
milliseconds since 1970 of the time the item was last modified
Throws:
TemplateException - is thrown whenever the item:
  • does not exist
  • is the wrong type (eg. a directory, not a file)

getPreloadData

public java.util.List getPreloadData()
                              throws TemplateException
Returns a list of objects (Strings) to pre-load the cache with.
Returns:
a List of Strings to preload the cache with

connectionOk

public boolean connectionOk()
                     throws TemplateException
Corresponds to checkCacheDir for file-system implementations.
Returns:
true if the connection is ok, otherwise false
Throws:
TemplateException - whenever the connection has failed, and cannot be re-established

setConnection

public void setConnection(java.lang.String connection)
Sets the connection for this retriever. Corresponds to setPath for file-system implementations.
Parameters:
connection - the connection string for this retriever

getConnection

public java.lang.String getConnection()
Gets the connection for this retriever. Corresponds to getPath for file-system implementations.
Returns:
the connection string used to connect to this retriever