|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
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 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| public class FlushTag extends TagSupport { |
|
45 |
| ServletCacheAdministrator admin = null; |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| String group = null; |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| String key = null; |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| String pattern = null; |
|
62 |
| String scope = null; |
|
63 |
| int cacheScope = -1; |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| private String language = null; |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
0
| public void setGroup(String group) {
|
|
77 |
0
| this.group = group;
|
|
78 |
| } |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
| |
|
85 |
| |
|
86 |
0
| public void setKey(String value) {
|
|
87 |
0
| this.key = value;
|
|
88 |
| } |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
0
| public void setLanguage(String value) {
|
|
96 |
0
| this.language = value;
|
|
97 |
| } |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
0
| public void setPattern(String value) {
|
|
105 |
0
| this.pattern = value;
|
|
106 |
| } |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
0
| public void setScope(String value) {
|
|
114 |
0
| if (value != null) {
|
|
115 |
0
| if (value.equalsIgnoreCase(ServletCacheAdministrator.SESSION_SCOPE_NAME)) {
|
|
116 |
0
| cacheScope = PageContext.SESSION_SCOPE;
|
|
117 |
0
| } else if (value.equalsIgnoreCase(ServletCacheAdministrator.APPLICATION_SCOPE_NAME)) {
|
|
118 |
0
| cacheScope = PageContext.APPLICATION_SCOPE;
|
|
119 |
| } |
|
120 |
| } |
|
121 |
| } |
|
122 |
| |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
0
| public int doStartTag() throws JspTagException {
|
|
130 |
0
| if (admin == null) {
|
|
131 |
0
| admin = ServletCacheAdministrator.getInstance(pageContext.getServletContext());
|
|
132 |
| } |
|
133 |
| |
|
134 |
0
| if (group != null)
|
|
135 |
| { |
|
136 |
0
| if (cacheScope >= 0) {
|
|
137 |
0
| Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
|
|
138 |
0
| cache.flushGroup(group);
|
|
139 |
| } else { |
|
140 |
0
| throw new JspTagException("A cache group was specified for flushing, but the scope wasn't supplied or was invalid");
|
|
141 |
| } |
|
142 |
0
| } else if (pattern != null)
|
|
143 |
| { |
|
144 |
0
| if (cacheScope >= 0) {
|
|
145 |
0
| Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
|
|
146 |
0
| cache.flushPattern(pattern);
|
|
147 |
| } else { |
|
148 |
0
| throw new JspTagException("A pattern was specified for flushing, but the scope wasn't supplied or was invalid");
|
|
149 |
| } |
|
150 |
0
| } else if (key == null)
|
|
151 |
| { |
|
152 |
0
| if (cacheScope >= 0) {
|
|
153 |
0
| admin.setFlushTime(cacheScope);
|
|
154 |
| } else { |
|
155 |
0
| admin.flushAll();
|
|
156 |
| } |
|
157 |
| } else |
|
158 |
| { |
|
159 |
0
| if (cacheScope >= 0) {
|
|
160 |
0
| String actualKey = admin.generateEntryKey(key, (HttpServletRequest) pageContext.getRequest(), cacheScope, language);
|
|
161 |
| |
|
162 |
0
| Cache cache = admin.getCache((HttpServletRequest) pageContext.getRequest(), cacheScope);
|
|
163 |
0
| cache.flushEntry(actualKey);
|
|
164 |
| } else { |
|
165 |
0
| throw new JspTagException("A cache key was specified for flushing, but the scope wasn't supplied or was invalid");
|
|
166 |
| } |
|
167 |
| } |
|
168 |
| |
|
169 |
0
| return SKIP_BODY;
|
|
170 |
| } |
|
171 |
| } |