1 24 package org.riotfamily.cachius.spring; 25 26 import javax.servlet.http.HttpServletRequest ; 27 28 import org.riotfamily.common.web.util.ServletUtils; 29 import org.springframework.beans.factory.BeanNameAware; 30 31 32 37 public abstract class AbstractCacheableController 38 implements CacheableController, BeanNameAware { 39 40 private String beanName; 41 42 public final void setBeanName(String beanName) { 43 this.beanName = beanName; 44 } 45 46 protected String getBeanName() { 47 return beanName; 48 } 49 50 57 public final String getCacheKey(HttpServletRequest request) { 58 if (bypassCache(request)) { 59 return null; 60 } 61 StringBuffer key = new StringBuffer (); 62 key.append(beanName).append(':'); 63 appendCacheKey(key, request); 64 return key.toString(); 65 } 66 67 71 protected boolean bypassCache(HttpServletRequest request) { 72 return false; 73 } 74 75 81 protected void appendCacheKey(StringBuffer key, HttpServletRequest request) { 82 key.append(ServletUtils.getOriginatingRequestUri(request)); 83 } 84 85 90 public long getTimeToLive() { 91 return 0; 92 } 93 94 100 public long getLastModified(HttpServletRequest request) { 101 return System.currentTimeMillis(); 102 } 103 104 } 105 | Popular Tags |