1 package de.halbekunst.juplo.cachecontrol;
3 import de.halbekunst.juplo.cachecontrol.AcceleratorFilter.AccelerationWrapper;
4 import de.halbekunst.juplo.cachecontrol.annotations.Cacheable;
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.web.servlet.HandlerInterceptor;
11 import org.springframework.web.servlet.ModelAndView;
17 public class CacheControlInterceptor implements HandlerInterceptor {
18 private final static Logger log = LoggerFactory.getLogger(CacheControlInterceptor.class);
21 private CacheControl cacheControl;
25 public boolean preHandle(
26 HttpServletRequest request,
27 HttpServletResponse response,
31 Cacheable cacheable = handler.getClass().getAnnotation(Cacheable.class);
32 if (cacheable == null) {
33 /** Der Handler ist nicht mit @Cacheable annotiert: keine Dekorationen anbringen! */
37 AccelerationWrapper wrapper = (AccelerationWrapper)request.getAttribute(AcceleratorFilter.RESPONSE_WRAPPER);
39 wrapper.supressGuessing();
41 /** CacheControll initialisieren (Handler nach annotierte Methoden scannen etc.) */
42 cacheControl.init(handler, wrapper);
44 if (cacheable.eager()) {
45 return cacheControl.decorate(request, response, handler);
53 public void postHandle(
54 HttpServletRequest request,
55 HttpServletResponse response,
57 ModelAndView modelAndView
60 cacheControl.decorate(request, response, handler);
64 public void afterCompletion(
65 HttpServletRequest request,
66 HttpServletResponse response,
67 Object handler, Exception ex
70 cacheControl.release();
75 public void setCacheControl(CacheControl cacheControl) {
76 this.cacheControl = cacheControl;