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 1101 2013-04-01 04:17:32Z run2000 $

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<java.lang.String> 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, Cache cache)
          Retrieves data of the appropriate type to be stored in the cache.
 

Method Detail

loadData

Cacheable loadData(java.lang.String location,
                   java.lang.String type,
                   Cache cache)
                   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
cache - the cache to which the item will be added
Returns:
a Cacheable object loaded from the data source
Throws:
TemplateException - the object could not be loaded

exists

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

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

java.util.List<java.lang.String> 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
Throws:
TemplateException

connectionOk

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

getConnection

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