org.riotfamily.cachius.spring
Class AbstractCacheableController

java.lang.Object
  extended by org.riotfamily.cachius.spring.AbstractCacheableController
All Implemented Interfaces:
CacheableController, BeanNameAware, Controller
Direct Known Subclasses:
AbstractMinifyController, AbstractResourceController, CssTemplateController, SiteListController, Txt2ImgController

public abstract class AbstractCacheableController
extends Object
implements CacheableController, BeanNameAware

Abstract base class for cacheable controllers.

Author:
Felix Gnass

Field Summary
 
Fields inherited from interface org.riotfamily.cachius.spring.CacheableController
CACHE_ETERNALLY
 
Constructor Summary
AbstractCacheableController()
           
 
Method Summary
protected  void appendCacheKey(StringBuffer key, HttpServletRequest request)
          Subclasses may overwrite this method to append values to the cache-key.
protected  boolean bypassCache(HttpServletRequest request)
          Returns whether the cache should be bypassed.
protected  String getBeanName()
           
 String getCacheKey(HttpServletRequest request)
          Returns the cache-key for the request.
protected  String getCacheKeyInternal(HttpServletRequest request)
          Returns the actual cache-key.
 long getLastModified(HttpServletRequest request)
          The default implementation returns System.currentTimeMillis() so that the item is refreshed as soon as it expires.
 long getTimeToLive()
          The default implementation returns 0 so that getLastModified(HttpServletRequest) is invoked every time the controller is requested.
 void setAddUriToCacheKey(boolean addUriToCacheKey)
          Sets whether the (originating) URI should be included in the cache-key.
 void setBeanName(String beanName)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.web.servlet.mvc.Controller
handleRequest
 

Constructor Detail

AbstractCacheableController

public AbstractCacheableController()
Method Detail

setBeanName

public final void setBeanName(String beanName)
Specified by:
setBeanName in interface BeanNameAware

getBeanName

protected String getBeanName()

setAddUriToCacheKey

public void setAddUriToCacheKey(boolean addUriToCacheKey)
Sets whether the (originating) URI should be included in the cache-key. Set this property to false if the controller looks the same on every page, i.e. does not dependent on the URI. The default is true which is safe (as it will rule out wrong content to be displayed due to identical cache-keys) but could lead to many identical cache items.

See Also:
getCacheKeyInternal(HttpServletRequest)

bypassCache

protected boolean bypassCache(HttpServletRequest request)
Returns whether the cache should be bypassed. The default implementation always returns false.


getCacheKey

public final String getCacheKey(HttpServletRequest request)
Returns the cache-key for the request. The call is delegated to getCacheKeyInternal(HttpServletRequest), unless bypassCache(HttpServletRequest) returns true.

Specified by:
getCacheKey in interface CacheableController

getCacheKeyInternal

protected String getCacheKeyInternal(HttpServletRequest request)
Returns the actual cache-key. Invoked by getCacheKey() if bypassCache() returned false.

The method creates a StringBuffer containing either the bean-name or the originating path and, in case of an include or forward, the nested path.

The StringBuffer is passed to appendCacheKey(StringBuffer, HttpServletRequest), allowing subclasses to add additional information.


appendCacheKey

protected void appendCacheKey(StringBuffer key,
                              HttpServletRequest request)
Subclasses may overwrite this method to append values to the cache-key. The default implementation does nothing.

See Also:
getCacheKeyInternal(HttpServletRequest)

getTimeToLive

public long getTimeToLive()
The default implementation returns 0 so that getLastModified(HttpServletRequest) is invoked every time the controller is requested.

Specified by:
getTimeToLive in interface CacheableController

getLastModified

public long getLastModified(HttpServletRequest request)
The default implementation returns System.currentTimeMillis() so that the item is refreshed as soon as it expires. Subclasses should override this method to return something reasonable.

Specified by:
getLastModified in interface CacheableController