org.riotfamily.cachius
Interface CacheHandler

All Known Implementing Classes:
ControllerCacheHandler, ResponseCapturingHandler, ServletWriterHandler, SessionIdCacheHandler, ZippedResponseHandler

public interface CacheHandler

Callback interface that can be passed to CacheService.handle(CacheHandler).

Since:
8.0
Author:
Felix Gnass [fgnass at neteye dot de]

Field Summary
static long CACHE_ETERNALLY
           
 
Method Summary
 String getCacheKey()
          Returns the key that is used to look up a previously cached version.
 long getLastModified()
          Returns the date (as timestamp) when the content was modified for the last time.
 long getTimeToLive()
          Returns the time in milliseconds that has to be elapsed since the last up-to-date check before another check is performed.
 void handleUncached()
          Callback method that is invoked when no CacheItem could be created.
 boolean updateCacheItem(CacheItem cacheItem)
          Callback method that is invoked when no cached version exists or the cached content is not up-to-date.
 void writeCacheItem(CacheItem cacheItem)
          Callback method that is invoked when an up-to-date CacheItem exists.
 

Field Detail

CACHE_ETERNALLY

static final long CACHE_ETERNALLY
See Also:
Constant Field Values
Method Detail

getCacheKey

String getCacheKey()
Returns the key that is used to look up a previously cached version. The key must include all values that govern the output. The key itself is not interpreted in any way and thus can have an arbitrary format.


getTimeToLive

long getTimeToLive()
Returns the time in milliseconds that has to be elapsed since the last up-to-date check before another check is performed. Implementors may return CACHE_ETERNALLY to indicate that the content should be cached eternally.


getLastModified

long getLastModified()
                     throws Exception
Returns the date (as timestamp) when the content was modified for the last time. The updateCacheItem(CacheItem) method will not be called unless this date is newer than the timestamp of the cached version.

Throws:
Exception

handleUncached

void handleUncached()
                    throws Exception
Callback method that is invoked when no CacheItem could be created. This can be the case when either getCacheKey() returns null, the cache is disabled or an unexpected error occurred.

Throws:
Exception

updateCacheItem

boolean updateCacheItem(CacheItem cacheItem)
                        throws Exception
Callback method that is invoked when no cached version exists or the cached content is not up-to-date. Implementors must obtain a Writer or an OutputStram by calling CacheItem.getWriter() or CacheItem.getOutputStream() and write their content into it.

Returns:
true if the CacheItem should be updated or false if it should be discarded.
Throws:
Exception

writeCacheItem

void writeCacheItem(CacheItem cacheItem)
                    throws IOException
Callback method that is invoked when an up-to-date CacheItem exists. Implementors must invoke one of the CacheItem.writeTo(...) to write the cached content to its destination.

Throws:
IOException