1 5 package com.opensymphony.oscache.web.tag; 6 7 import com.opensymphony.oscache.base.Cache; 8 import com.opensymphony.oscache.web.ServletCacheAdministrator; 9 10 import javax.servlet.http.HttpServletRequest ; 11 import javax.servlet.jsp.JspTagException ; 12 import javax.servlet.jsp.PageContext ; 13 import javax.servlet.jsp.tagext.TagSupport ; 14 15 44 public class FlushTag extends TagSupport { 45 ServletCacheAdministrator admin = null; 46 47 51 String group = null; 52 53 56 String key = null; 57 58 61 String pattern = null; 62 String scope = null; 63 int cacheScope = -1; 64 65 68 private String language = null; 69 70 76 public void setGroup(String group) { 77 this.group = group; 78 } 79 80 86 public void setKey(String value) { 87 this.key = value; 88 } 89 90 95 public void setLanguage(String value) { 96 this.language = value; 97 } 98 99 104 public void setPattern(String value) { 105 this.pattern = value; 106 } 107 108 113 public void setScope(String value) { 114 if (value != null) { 115 if (value.equalsIgnoreCase(ServletCacheAdministrator.SESSION_SCOPE_NAME)) { 116 cacheScope = PageContext.SESSION_SCOPE; 117 } else if (value.equalsIgnoreCase(ServletCacheAdministrator.APPLICATION_SCOPE_NAME)) { 118 cacheScope = PageContext.APPLICATION_SCOPE; 119 } 120 } 121 } 122 123 129 public int doStartTag() throws JspTagException { 130 if (admin == null) { 131 admin = ServletCacheAdministrator.getInstance(pageContext.getServletContext()); 132 } 133 134 if (group != null) { 136 if (cacheScope >= 0) { 137 Cache cache = admin.getCache((HttpServletRequest ) pageContext.getRequest(), cacheScope); 138 cache.flushGroup(group); 139 } else { 140 throw new JspTagException ("A cache group was specified for flushing, but the scope wasn't supplied or was invalid"); 141 } 142 } else if (pattern != null) { 144 if (cacheScope >= 0) { 145 Cache cache = admin.getCache((HttpServletRequest ) pageContext.getRequest(), cacheScope); 146 cache.flushPattern(pattern); 147 } else { 148 throw new JspTagException ("A pattern was specified for flushing, but the scope wasn't supplied or was invalid"); 149 } 150 } else if (key == null) { 152 if (cacheScope >= 0) { 153 admin.setFlushTime(cacheScope); 154 } else { 155 admin.flushAll(); 156 } 157 } else { 159 if (cacheScope >= 0) { 160 String actualKey = admin.generateEntryKey(key, (HttpServletRequest ) pageContext.getRequest(), cacheScope, language); 161 162 Cache cache = admin.getCache((HttpServletRequest ) pageContext.getRequest(), cacheScope); 163 cache.flushEntry(actualKey); 164 } else { 165 throw new JspTagException ("A cache key was specified for flushing, but the scope wasn't supplied or was invalid"); 166 } 167 } 168 169 return SKIP_BODY; 170 } 171 } 172 | Popular Tags |