org.riotfamily.cachius.servlet
Class SessionIdCacheHandler

java.lang.Object
  extended by org.riotfamily.cachius.servlet.SessionIdCacheHandler
All Implemented Interfaces:
CacheHandler
Direct Known Subclasses:
ResponseCapturingHandler, ServletWriterHandler

public abstract class SessionIdCacheHandler
extends Object
implements CacheHandler

Abstract CacheHandler that can cache content containing links with jsessionIds. The actual sessionIds are replaced by a special token which in turn is replaced with the current sessionId upon rendering.


Field Summary
 
Fields inherited from interface org.riotfamily.cachius.CacheHandler
CACHE_ETERNALLY
 
Constructor Summary
SessionIdCacheHandler(HttpServletRequest request, CacheKeyAugmentor cacheKeyAugmentor)
           
 
Method Summary
protected  void augmentCacheKey(StringBuffer key)
           
 String getCacheKey()
          Returns the key that is used to look up a previously cached version.
protected abstract  String getCacheKeyInternal()
           
 long getLastModified()
          Returns the date (as timestamp) when the content was modified for the last time.
protected  HttpServletRequest getRequest()
           
protected  SessionIdEncoder getSessionIdEncoder()
           
 long getTimeToLive()
          Returns the time in milliseconds that has to be elapsed since the last up-to-date check before another check is performed.
protected  void postProcess(CacheItem cacheItem)
           
 boolean updateCacheItem(CacheItem cacheItem)
          Callback method that is invoked when no cached version exists or the cached content is not up-to-date.
protected abstract  boolean updateCacheItemInternal(CacheItem cacheItem)
           
 void writeCacheItem(CacheItem cacheItem)
          Callback method that is invoked when an up-to-date CacheItem exists.
protected abstract  void writeCacheItemInternal(CacheItem cacheItem)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.riotfamily.cachius.CacheHandler
handleUncached
 

Constructor Detail

SessionIdCacheHandler

public SessionIdCacheHandler(HttpServletRequest request,
                             CacheKeyAugmentor cacheKeyAugmentor)
Method Detail

getRequest

protected HttpServletRequest getRequest()

getSessionIdEncoder

protected SessionIdEncoder getSessionIdEncoder()

getCacheKey

public final String getCacheKey()
Description copied from interface: CacheHandler
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.

Specified by:
getCacheKey in interface CacheHandler

getCacheKeyInternal

protected abstract String getCacheKeyInternal()

augmentCacheKey

protected void augmentCacheKey(StringBuffer key)

getLastModified

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

Specified by:
getLastModified in interface CacheHandler
Throws:
Exception

getTimeToLive

public long getTimeToLive()
Description copied from interface: CacheHandler
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 CacheHandler.CACHE_ETERNALLY to indicate that the content should be cached eternally.

Specified by:
getTimeToLive in interface CacheHandler

updateCacheItem

public final boolean updateCacheItem(CacheItem cacheItem)
                              throws Exception
Description copied from interface: CacheHandler
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.

Specified by:
updateCacheItem in interface CacheHandler
Returns:
true if the CacheItem should be updated or false if it should be discarded.
Throws:
Exception

updateCacheItemInternal

protected abstract boolean updateCacheItemInternal(CacheItem cacheItem)
                                            throws Exception
Throws:
Exception

postProcess

protected void postProcess(CacheItem cacheItem)
                    throws Exception
Throws:
Exception

writeCacheItem

public final void writeCacheItem(CacheItem cacheItem)
                          throws IOException
Description copied from interface: CacheHandler
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.

Specified by:
writeCacheItem in interface CacheHandler
Throws:
IOException

writeCacheItemInternal

protected abstract void writeCacheItemInternal(CacheItem cacheItem)
                                        throws IOException
Throws:
IOException