org.riotfamily.cachius.spring
Class CacheableControllerHandlerAdapter

java.lang.Object
  extended by org.riotfamily.cachius.spring.CacheableControllerHandlerAdapter
All Implemented Interfaces:
ApplicationContextAware, Ordered, HandlerAdapter

public class CacheableControllerHandlerAdapter
extends Object
implements HandlerAdapter, ApplicationContextAware, Ordered

Adapter that handles cacheable controllers.

The adapter checks if a Controller is cacheable and whether there is an up-to-date cache item which can be served. If not, the controller's handleRequest() method is invoked and the output is captured and written to the cache.

Since 6.5 the adapter does no longer support regular controllers. In order to support both cacheable and non-cacheable controllers you have to add a SimpleControllerHandlerAdapter to your context manually.

Author:
Felix Gnass

Field Summary
 
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
 
Constructor Summary
CacheableControllerHandlerAdapter(CacheService cacheService)
           
CacheableControllerHandlerAdapter(CacheService cacheService, CacheKeyAugmentor cacheKeyAugmentor)
           
 
Method Summary
protected  String getCacheKey(CacheableController controller, HttpServletRequest request)
           
 long getLastModified(HttpServletRequest request, Object handler)
          Returns the lastModified date as reported by the CacheService.
 int getOrder()
          Returns the order in which this HandlerAdapter is processed.
 ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
           
 void setApplicationContext(ApplicationContext context)
           
 void setCacheKeyAugmentor(CacheKeyAugmentor cacheKeyAugmentor)
           
 void setOrder(int order)
          Set the order in which this HandlerAdapter is processed.
 boolean supports(Object handler)
          Returns true if handler implements the CacheableController interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CacheableControllerHandlerAdapter

public CacheableControllerHandlerAdapter(CacheService cacheService)

CacheableControllerHandlerAdapter

public CacheableControllerHandlerAdapter(CacheService cacheService,
                                         CacheKeyAugmentor cacheKeyAugmentor)
Method Detail

getOrder

public int getOrder()
Returns the order in which this HandlerAdapter is processed.

Specified by:
getOrder in interface Ordered

setOrder

public void setOrder(int order)
Set the order in which this HandlerAdapter is processed.


setApplicationContext

public void setApplicationContext(ApplicationContext context)
Specified by:
setApplicationContext in interface ApplicationContextAware

setCacheKeyAugmentor

public void setCacheKeyAugmentor(CacheKeyAugmentor cacheKeyAugmentor)

supports

public boolean supports(Object handler)
Returns true if handler implements the CacheableController interface.

Specified by:
supports in interface HandlerAdapter

handle

public final ModelAndView handle(HttpServletRequest request,
                                 HttpServletResponse response,
                                 Object handler)
                          throws Exception
Specified by:
handle in interface HandlerAdapter
Throws:
Exception

getLastModified

public final long getLastModified(HttpServletRequest request,
                                  Object handler)
Returns the lastModified date as reported by the CacheService.

Specified by:
getLastModified in interface HandlerAdapter

getCacheKey

protected final String getCacheKey(CacheableController controller,
                                   HttpServletRequest request)