|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package com.opensymphony.oscache.web.filter; |
|
6 |
| |
|
7 |
| import com.opensymphony.oscache.base.Cache; |
|
8 |
| import com.opensymphony.oscache.base.Config; |
|
9 |
| import com.opensymphony.oscache.base.EntryRefreshPolicy; |
|
10 |
| import com.opensymphony.oscache.base.NeedsRefreshException; |
|
11 |
| import com.opensymphony.oscache.util.ClassLoaderUtil; |
|
12 |
| import com.opensymphony.oscache.util.StringUtil; |
|
13 |
| import com.opensymphony.oscache.web.ServletCacheAdministrator; |
|
14 |
| |
|
15 |
| import org.apache.commons.logging.Log; |
|
16 |
| import org.apache.commons.logging.LogFactory; |
|
17 |
| |
|
18 |
| import java.io.IOException; |
|
19 |
| import java.util.List; |
|
20 |
| import java.util.Properties; |
|
21 |
| |
|
22 |
| import javax.servlet.*; |
|
23 |
| import javax.servlet.http.HttpServletRequest; |
|
24 |
| import javax.servlet.http.HttpServletResponse; |
|
25 |
| import javax.servlet.jsp.PageContext; |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| public class CacheFilter implements Filter, ICacheKeyProvider, ICacheGroupsProvider { |
|
38 |
| |
|
39 |
| public static final String HEADER_LAST_MODIFIED = "Last-Modified"; |
|
40 |
| public static final String HEADER_CONTENT_TYPE = "Content-Type"; |
|
41 |
| public static final String HEADER_CONTENT_ENCODING = "Content-Encoding"; |
|
42 |
| public static final String HEADER_EXPIRES = "Expires"; |
|
43 |
| public static final String HEADER_IF_MODIFIED_SINCE = "If-Modified-Since"; |
|
44 |
| public static final String HEADER_CACHE_CONTROL = "Cache-Control"; |
|
45 |
| public static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding"; |
|
46 |
| |
|
47 |
| |
|
48 |
| public static final int FRAGMENT_AUTODETECT = -1; |
|
49 |
| public static final int FRAGMENT_NO = 0; |
|
50 |
| public static final int FRAGMENT_YES = 1; |
|
51 |
| |
|
52 |
| |
|
53 |
| public static final int NOCACHE_OFF = 0; |
|
54 |
| public static final int NOCACHE_SESSION_ID_IN_URL = 1; |
|
55 |
| |
|
56 |
| |
|
57 |
| public static final long LAST_MODIFIED_OFF = 0; |
|
58 |
| public static final long LAST_MODIFIED_ON = 1; |
|
59 |
| public static final long LAST_MODIFIED_INITIAL = -1; |
|
60 |
| |
|
61 |
| |
|
62 |
| public static final long EXPIRES_OFF = 0; |
|
63 |
| public static final long EXPIRES_ON = 1; |
|
64 |
| public static final long EXPIRES_TIME = -1; |
|
65 |
| |
|
66 |
| |
|
67 |
| public static final long MAX_AGE_NO_INIT = Long.MIN_VALUE; |
|
68 |
| public static final long MAX_AGE_TIME = Long.MAX_VALUE; |
|
69 |
| |
|
70 |
| |
|
71 |
| private final static String REQUEST_FILTERED = "__oscache_filtered__"; |
|
72 |
| private String requestFiltered; |
|
73 |
| |
|
74 |
| |
|
75 |
| private EntryRefreshPolicy expiresRefreshPolicy; |
|
76 |
| |
|
77 |
| |
|
78 |
| private final Log log = LogFactory.getLog(this.getClass()); |
|
79 |
| |
|
80 |
| |
|
81 |
| private FilterConfig config; |
|
82 |
| private ServletCacheAdministrator admin = null; |
|
83 |
| private int cacheScope = PageContext.APPLICATION_SCOPE; |
|
84 |
| private int fragment = FRAGMENT_AUTODETECT; |
|
85 |
| private int time = 60 * 60; |
|
86 |
| private String cron = null; |
|
87 |
| private int nocache = NOCACHE_OFF; |
|
88 |
| private long lastModified = LAST_MODIFIED_INITIAL; |
|
89 |
| private long expires = EXPIRES_ON; |
|
90 |
| private long cacheControlMaxAge = -60; |
|
91 |
| private ICacheKeyProvider cacheKeyProvider = this; |
|
92 |
| private ICacheGroupsProvider cacheGroupsProvider = this; |
|
93 |
| private List disableCacheOnMethods = null; |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
0
| public void destroy() {
|
|
99 |
| |
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
0
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
|
|
115 |
0
| if (log.isInfoEnabled()) {
|
|
116 |
0
| log.info("OSCache: filter in scope " + cacheScope);
|
|
117 |
| } |
|
118 |
| |
|
119 |
| |
|
120 |
0
| if (isFilteredBefore(request) || !isCacheableInternal(request)) {
|
|
121 |
0
| chain.doFilter(request, response);
|
|
122 |
0
| return;
|
|
123 |
| } |
|
124 |
0
| request.setAttribute(requestFiltered, Boolean.TRUE);
|
|
125 |
| |
|
126 |
0
| HttpServletRequest httpRequest = (HttpServletRequest) request;
|
|
127 |
| |
|
128 |
| |
|
129 |
0
| boolean fragmentRequest = isFragment(httpRequest);
|
|
130 |
| |
|
131 |
| |
|
132 |
0
| Cache cache;
|
|
133 |
0
| if (cacheScope == PageContext.SESSION_SCOPE) {
|
|
134 |
0
| cache = admin.getSessionScopeCache(httpRequest.getSession(true));
|
|
135 |
| } else { |
|
136 |
0
| cache = admin.getAppScopeCache(config.getServletContext());
|
|
137 |
| } |
|
138 |
| |
|
139 |
| |
|
140 |
0
| String key = cacheKeyProvider.createCacheKey(httpRequest, admin, cache);
|
|
141 |
| |
|
142 |
0
| try {
|
|
143 |
0
| ResponseContent respContent = (ResponseContent) cache.getFromCache(key, time, cron);
|
|
144 |
| |
|
145 |
0
| if (log.isInfoEnabled()) {
|
|
146 |
0
| log.info("OSCache: Using cached entry for " + key);
|
|
147 |
| } |
|
148 |
| |
|
149 |
0
| boolean acceptsGZip = false;
|
|
150 |
0
| if ((!fragmentRequest) && (lastModified != LAST_MODIFIED_OFF)) {
|
|
151 |
0
| long clientLastModified = httpRequest.getDateHeader(HEADER_IF_MODIFIED_SINCE);
|
|
152 |
| |
|
153 |
| |
|
154 |
| |
|
155 |
0
| if ((clientLastModified != -1) && (clientLastModified >= respContent.getLastModified())) {
|
|
156 |
0
| ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
|
|
157 |
0
| return;
|
|
158 |
| } |
|
159 |
| |
|
160 |
0
| acceptsGZip = respContent.isContentGZiped() && acceptsGZipEncoding(httpRequest);
|
|
161 |
| } |
|
162 |
| |
|
163 |
0
| respContent.writeTo(response, fragmentRequest, acceptsGZip);
|
|
164 |
| |
|
165 |
| |
|
166 |
| } catch (NeedsRefreshException nre) { |
|
167 |
0
| boolean updateSucceeded = false;
|
|
168 |
| |
|
169 |
0
| try {
|
|
170 |
0
| if (log.isInfoEnabled()) {
|
|
171 |
0
| log.info("OSCache: New cache entry, cache stale or cache scope flushed for " + key);
|
|
172 |
| } |
|
173 |
| |
|
174 |
0
| CacheHttpServletResponseWrapper cacheResponse = new CacheHttpServletResponseWrapper((HttpServletResponse) response, fragmentRequest, time * 1000L, lastModified, expires, cacheControlMaxAge);
|
|
175 |
0
| chain.doFilter(request, cacheResponse);
|
|
176 |
0
| cacheResponse.flushBuffer();
|
|
177 |
| |
|
178 |
| |
|
179 |
0
| if (isCacheableInternal(cacheResponse)) {
|
|
180 |
| |
|
181 |
0
| String[] groups = cacheGroupsProvider.createCacheGroups(httpRequest, admin, cache);
|
|
182 |
| |
|
183 |
0
| cache.putInCache(key, cacheResponse.getContent(), groups, expiresRefreshPolicy, null);
|
|
184 |
0
| updateSucceeded = true;
|
|
185 |
0
| if (log.isInfoEnabled()) {
|
|
186 |
0
| log.info("OSCache: New entry added to the cache with key " + key);
|
|
187 |
| } |
|
188 |
| } |
|
189 |
| } finally { |
|
190 |
0
| if (!updateSucceeded) {
|
|
191 |
0
| cache.cancelUpdate(key);
|
|
192 |
| } |
|
193 |
| } |
|
194 |
| } |
|
195 |
| } |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
| |
|
200 |
| |
|
201 |
| |
|
202 |
| |
|
203 |
| |
|
204 |
| |
|
205 |
| |
|
206 |
| |
|
207 |
| |
|
208 |
0
| public void init(FilterConfig filterConfig) {
|
|
209 |
| |
|
210 |
0
| config = filterConfig;
|
|
211 |
| |
|
212 |
0
| log.info("OSCache: Initializing CacheFilter with filter name " + config.getFilterName());
|
|
213 |
| |
|
214 |
| |
|
215 |
0
| requestFiltered = REQUEST_FILTERED + config.getFilterName();
|
|
216 |
0
| log.info("Request filter attribute is " + requestFiltered);
|
|
217 |
| |
|
218 |
| |
|
219 |
0
| Properties props = null;
|
|
220 |
0
| try {
|
|
221 |
0
| String propertiesfile = config.getInitParameter("oscache-properties-file");
|
|
222 |
| |
|
223 |
0
| if (propertiesfile != null && propertiesfile.length() > 0) {
|
|
224 |
0
| props = Config.loadProperties(propertiesfile, "CacheFilter with filter name '" + config.getFilterName()+ "'");
|
|
225 |
| } |
|
226 |
| } catch (Exception e) { |
|
227 |
0
| log.info("OSCache: Init parameter 'oscache-properties-file' not set, using default.");
|
|
228 |
| } |
|
229 |
0
| admin = ServletCacheAdministrator.getInstance(config.getServletContext(), props);
|
|
230 |
| |
|
231 |
| |
|
232 |
0
| String timeParam = config.getInitParameter("time");
|
|
233 |
0
| if (timeParam != null) {
|
|
234 |
0
| try {
|
|
235 |
0
| setTime(Integer.parseInt(timeParam));
|
|
236 |
| } catch (NumberFormatException nfe) { |
|
237 |
0
| log.error("OSCache: Unexpected value for the init parameter 'time', defaulting to one hour. Message=" + nfe.getMessage());
|
|
238 |
| } |
|
239 |
| } |
|
240 |
| |
|
241 |
| |
|
242 |
0
| String scopeParam = config.getInitParameter("scope");
|
|
243 |
0
| if (scopeParam != null) {
|
|
244 |
0
| if ("session".equalsIgnoreCase(scopeParam)) {
|
|
245 |
0
| setCacheScope(PageContext.SESSION_SCOPE);
|
|
246 |
0
| } else if ("application".equalsIgnoreCase(scopeParam)) {
|
|
247 |
0
| setCacheScope(PageContext.APPLICATION_SCOPE);
|
|
248 |
| } else { |
|
249 |
0
| log.error("OSCache: Wrong value '" + scopeParam + "' for init parameter 'scope', defaulting to 'application'.");
|
|
250 |
| } |
|
251 |
| |
|
252 |
| } |
|
253 |
| |
|
254 |
| |
|
255 |
0
| setCron(config.getInitParameter("cron"));
|
|
256 |
| |
|
257 |
| |
|
258 |
0
| String fragmentParam = config.getInitParameter("fragment");
|
|
259 |
0
| if (fragmentParam != null) {
|
|
260 |
0
| if ("no".equalsIgnoreCase(fragmentParam)) {
|
|
261 |
0
| setFragment(FRAGMENT_NO);
|
|
262 |
0
| } else if ("yes".equalsIgnoreCase(fragmentParam)) {
|
|
263 |
0
| setFragment(FRAGMENT_YES);
|
|
264 |
0
| } else if ("auto".equalsIgnoreCase(fragmentParam)) {
|
|
265 |
0
| setFragment(FRAGMENT_AUTODETECT);
|
|
266 |
| } else { |
|
267 |
0
| log.error("OSCache: Wrong value '" + fragmentParam + "' for init parameter 'fragment', defaulting to 'auto detect'.");
|
|
268 |
| } |
|
269 |
| } |
|
270 |
| |
|
271 |
| |
|
272 |
0
| String nocacheParam = config.getInitParameter("nocache");
|
|
273 |
0
| if (nocacheParam != null) {
|
|
274 |
0
| if ("off".equalsIgnoreCase(nocacheParam)) {
|
|
275 |
0
| nocache = NOCACHE_OFF;
|
|
276 |
0
| } else if ("sessionIdInURL".equalsIgnoreCase(nocacheParam)) {
|
|
277 |
0
| nocache = NOCACHE_SESSION_ID_IN_URL;
|
|
278 |
| } else { |
|
279 |
0
| log.error("OSCache: Wrong value '" + nocacheParam + "' for init parameter 'nocache', defaulting to 'off'.");
|
|
280 |
| } |
|
281 |
| } |
|
282 |
| |
|
283 |
| |
|
284 |
0
| String lastModifiedParam = config.getInitParameter("lastModified");
|
|
285 |
0
| if (lastModifiedParam != null) {
|
|
286 |
0
| if ("off".equalsIgnoreCase(lastModifiedParam)) {
|
|
287 |
0
| lastModified = LAST_MODIFIED_OFF;
|
|
288 |
0
| } else if ("on".equalsIgnoreCase(lastModifiedParam)) {
|
|
289 |
0
| lastModified = LAST_MODIFIED_ON;
|
|
290 |
0
| } else if ("initial".equalsIgnoreCase(lastModifiedParam)) {
|
|
291 |
0
| lastModified = LAST_MODIFIED_INITIAL;
|
|
292 |
| } else { |
|
293 |
0
| log.error("OSCache: Wrong value '" + lastModifiedParam + "' for init parameter 'lastModified', defaulting to 'initial'.");
|
|
294 |
| } |
|
295 |
| } |
|
296 |
| |
|
297 |
| |
|
298 |
0
| String expiresParam = config.getInitParameter("expires");
|
|
299 |
0
| if (expiresParam != null) {
|
|
300 |
0
| if ("off".equalsIgnoreCase(expiresParam)) {
|
|
301 |
0
| setExpires(EXPIRES_OFF);
|
|
302 |
0
| } else if ("on".equalsIgnoreCase(expiresParam)) {
|
|
303 |
0
| setExpires(EXPIRES_ON);
|
|
304 |
0
| } else if ("time".equalsIgnoreCase(expiresParam)) {
|
|
305 |
0
| setExpires(EXPIRES_TIME);
|
|
306 |
| } else { |
|
307 |
0
| log.error("OSCache: Wrong value '" + expiresParam + "' for init parameter 'expires', defaulting to 'on'.");
|
|
308 |
| } |
|
309 |
| } |
|
310 |
| |
|
311 |
| |
|
312 |
0
| String cacheControlMaxAgeParam = config.getInitParameter("max-age");
|
|
313 |
0
| if (cacheControlMaxAgeParam != null) {
|
|
314 |
0
| if (cacheControlMaxAgeParam.equalsIgnoreCase("no init")) {
|
|
315 |
0
| setCacheControlMaxAge(MAX_AGE_NO_INIT);
|
|
316 |
0
| } else if (cacheControlMaxAgeParam.equalsIgnoreCase("time")) {
|
|
317 |
0
| setCacheControlMaxAge(MAX_AGE_TIME);
|
|
318 |
| } else { |
|
319 |
0
| try {
|
|
320 |
0
| setCacheControlMaxAge(Long.parseLong(cacheControlMaxAgeParam));
|
|
321 |
| } catch (NumberFormatException nfe) { |
|
322 |
0
| log.error("OSCache: Unexpected value for the init parameter 'max-age', defaulting to '60'. Message=" + nfe.getMessage());
|
|
323 |
| } |
|
324 |
| } |
|
325 |
| } |
|
326 |
| |
|
327 |
| |
|
328 |
0
| ICacheKeyProvider cacheKeyProviderParam = (ICacheKeyProvider)instantiateFromInitParam("ICacheKeyProvider", ICacheKeyProvider.class, this.getClass().getName());
|
|
329 |
0
| if (cacheKeyProviderParam != null) {
|
|
330 |
0
| setCacheKeyProvider(cacheKeyProviderParam);
|
|
331 |
| } |
|
332 |
| |
|
333 |
| |
|
334 |
0
| ICacheGroupsProvider cacheGroupsProviderParam = (ICacheGroupsProvider)instantiateFromInitParam("ICacheGroupsProvider", ICacheGroupsProvider.class, this.getClass().getName());
|
|
335 |
0
| if (cacheGroupsProviderParam != null) {
|
|
336 |
0
| setCacheGroupsProvider(cacheGroupsProviderParam);
|
|
337 |
| } |
|
338 |
| |
|
339 |
| |
|
340 |
0
| EntryRefreshPolicy expiresRefreshPolicyParam = (EntryRefreshPolicy)instantiateFromInitParam("EntryRefreshPolicy", EntryRefreshPolicy.class, ExpiresRefreshPolicy.class.getName());
|
|
341 |
0
| if (expiresRefreshPolicyParam != null) {
|
|
342 |
0
| setExpiresRefreshPolicy(expiresRefreshPolicyParam);
|
|
343 |
| } else { |
|
344 |
| |
|
345 |
0
| setExpiresRefreshPolicy(new ExpiresRefreshPolicy(time));
|
|
346 |
| } |
|
347 |
| |
|
348 |
| |
|
349 |
0
| String disableCacheOnMethodsParam = config.getInitParameter("disableCacheOnMethods");
|
|
350 |
0
| if (StringUtil.hasLength(disableCacheOnMethodsParam)) {
|
|
351 |
0
| disableCacheOnMethods = StringUtil.split(disableCacheOnMethodsParam, ',');
|
|
352 |
| |
|
353 |
| } |
|
354 |
| |
|
355 |
| } |
|
356 |
| |
|
357 |
0
| private Object instantiateFromInitParam(String classInitParam, Class interfaceClass, String defaultObjectName) {
|
|
358 |
0
| String className = config.getInitParameter(classInitParam);
|
|
359 |
0
| if (className != null) {
|
|
360 |
0
| try {
|
|
361 |
0
| Class clazz = ClassLoaderUtil.loadClass(className, this.getClass());
|
|
362 |
0
| if (!interfaceClass.isAssignableFrom(clazz)) {
|
|
363 |
0
| log.error("OSCache: Specified class '" + className + "' does not implement" + interfaceClass.getName() + ". Using default " + defaultObjectName + ".");
|
|
364 |
0
| return null;
|
|
365 |
| } else { |
|
366 |
0
| return clazz.newInstance();
|
|
367 |
| } |
|
368 |
| } catch (ClassNotFoundException e) { |
|
369 |
0
| log.error("OSCache: Class '" + className + "' not found. Defaulting to " + defaultObjectName + ".", e);
|
|
370 |
| } catch (InstantiationException e) { |
|
371 |
0
| log.error("OSCache: Class '" + className + "' could not be instantiated because it is not a concrete class. Using default object " + defaultObjectName + ".", e);
|
|
372 |
| } catch (IllegalAccessException e) { |
|
373 |
0
| log.error("OSCache: Class '"+ className+ "' could not be instantiated because it is not public. Using default object " + defaultObjectName + ".", e);
|
|
374 |
| } |
|
375 |
| } |
|
376 |
0
| return null;
|
|
377 |
| } |
|
378 |
| |
|
379 |
| |
|
380 |
| |
|
381 |
| |
|
382 |
| |
|
383 |
0
| public String createCacheKey(HttpServletRequest httpRequest, ServletCacheAdministrator scAdmin, Cache cache) {
|
|
384 |
0
| return scAdmin.generateEntryKey(null, httpRequest, cacheScope);
|
|
385 |
| } |
|
386 |
| |
|
387 |
| |
|
388 |
| |
|
389 |
| |
|
390 |
| |
|
391 |
0
| public String[] createCacheGroups(HttpServletRequest httpRequest, ServletCacheAdministrator scAdmin, Cache cache) {
|
|
392 |
0
| return null;
|
|
393 |
| } |
|
394 |
| |
|
395 |
| |
|
396 |
| |
|
397 |
| |
|
398 |
| |
|
399 |
| |
|
400 |
| |
|
401 |
| |
|
402 |
| |
|
403 |
| |
|
404 |
| |
|
405 |
| |
|
406 |
| |
|
407 |
0
| public boolean isFragment(HttpServletRequest request) {
|
|
408 |
0
| if (fragment == FRAGMENT_AUTODETECT) {
|
|
409 |
0
| return request.getAttribute("javax.servlet.include.request_uri") != null;
|
|
410 |
| } else { |
|
411 |
0
| return (fragment == FRAGMENT_NO) ? false : true;
|
|
412 |
| } |
|
413 |
| } |
|
414 |
| |
|
415 |
| |
|
416 |
| |
|
417 |
| |
|
418 |
| |
|
419 |
| |
|
420 |
| |
|
421 |
| |
|
422 |
| |
|
423 |
| |
|
424 |
0
| public boolean isFilteredBefore(ServletRequest request) {
|
|
425 |
0
| return request.getAttribute(requestFiltered) != null;
|
|
426 |
| } |
|
427 |
| |
|
428 |
| |
|
429 |
| |
|
430 |
| |
|
431 |
| |
|
432 |
| |
|
433 |
| |
|
434 |
0
| private final boolean isCacheableInternal(ServletRequest request) {
|
|
435 |
0
| final boolean cacheable = isCacheable(request);
|
|
436 |
| |
|
437 |
0
| if (log.isDebugEnabled()) {
|
|
438 |
0
| log.debug("OSCache: the request " + ((cacheable) ? "is" : "is not") + " cachable.");
|
|
439 |
| } |
|
440 |
| |
|
441 |
0
| return cacheable;
|
|
442 |
| } |
|
443 |
| |
|
444 |
| |
|
445 |
| |
|
446 |
| |
|
447 |
| |
|
448 |
| |
|
449 |
| |
|
450 |
| |
|
451 |
0
| public boolean isCacheable(ServletRequest request) {
|
|
452 |
0
| boolean cacheable = request instanceof HttpServletRequest;
|
|
453 |
| |
|
454 |
0
| if (cacheable) {
|
|
455 |
0
| HttpServletRequest requestHttp = (HttpServletRequest) request;
|
|
456 |
| |
|
457 |
0
| if ((disableCacheOnMethods != null) && (disableCacheOnMethods.contains(requestHttp.getMethod()))) {
|
|
458 |
0
| return false;
|
|
459 |
| } |
|
460 |
0
| if (nocache == NOCACHE_SESSION_ID_IN_URL) {
|
|
461 |
0
| cacheable = !requestHttp.isRequestedSessionIdFromURL();
|
|
462 |
| } |
|
463 |
| } |
|
464 |
| |
|
465 |
0
| return cacheable;
|
|
466 |
| } |
|
467 |
| |
|
468 |
| |
|
469 |
| |
|
470 |
| |
|
471 |
| |
|
472 |
| |
|
473 |
| |
|
474 |
0
| private final boolean isCacheableInternal(CacheHttpServletResponseWrapper cacheResponse) {
|
|
475 |
0
| final boolean cacheable = isCacheable(cacheResponse);
|
|
476 |
| |
|
477 |
0
| if (log.isDebugEnabled()) {
|
|
478 |
0
| log.debug("OSCache: the response " + ((cacheable) ? "is" : "is not") + " cachable.");
|
|
479 |
| } |
|
480 |
| |
|
481 |
0
| return cacheable;
|
|
482 |
| } |
|
483 |
| |
|
484 |
| |
|
485 |
| |
|
486 |
| |
|
487 |
| |
|
488 |
| |
|
489 |
| |
|
490 |
| |
|
491 |
0
| public boolean isCacheable(CacheHttpServletResponseWrapper cacheResponse) {
|
|
492 |
| |
|
493 |
| |
|
494 |
0
| return cacheResponse.getStatus() == HttpServletResponse.SC_OK;
|
|
495 |
| } |
|
496 |
| |
|
497 |
| |
|
498 |
| |
|
499 |
| |
|
500 |
| |
|
501 |
| |
|
502 |
| |
|
503 |
0
| public boolean acceptsGZipEncoding(HttpServletRequest request) {
|
|
504 |
0
| String acceptEncoding = request.getHeader(HEADER_ACCEPT_ENCODING);
|
|
505 |
0
| return (acceptEncoding != null) && (acceptEncoding.indexOf("gzip") != -1);
|
|
506 |
| } |
|
507 |
| |
|
508 |
| |
|
509 |
| |
|
510 |
| |
|
511 |
| |
|
512 |
| |
|
513 |
| |
|
514 |
| |
|
515 |
| |
|
516 |
0
| public long getCacheControlMaxAge() {
|
|
517 |
0
| if ((cacheControlMaxAge == MAX_AGE_NO_INIT) || (cacheControlMaxAge == MAX_AGE_TIME)) {
|
|
518 |
0
| return cacheControlMaxAge;
|
|
519 |
| } |
|
520 |
0
| return - cacheControlMaxAge;
|
|
521 |
| } |
|
522 |
| |
|
523 |
| |
|
524 |
| |
|
525 |
| |
|
526 |
| |
|
527 |
| |
|
528 |
| |
|
529 |
| |
|
530 |
| |
|
531 |
| |
|
532 |
0
| public void setCacheControlMaxAge(long cacheControlMaxAge) {
|
|
533 |
0
| if ((cacheControlMaxAge == MAX_AGE_NO_INIT) || (cacheControlMaxAge == MAX_AGE_TIME)) {
|
|
534 |
0
| this.cacheControlMaxAge = cacheControlMaxAge;
|
|
535 |
0
| } else if (cacheControlMaxAge >= 0) {
|
|
536 |
| |
|
537 |
| |
|
538 |
0
| this.cacheControlMaxAge = - cacheControlMaxAge;
|
|
539 |
| } else { |
|
540 |
0
| log.warn("OSCache: 'max-age' must be at least a positive integer, defaulting to '60'. ");
|
|
541 |
0
| this.cacheControlMaxAge = -60;
|
|
542 |
| } |
|
543 |
| } |
|
544 |
| |
|
545 |
| |
|
546 |
| |
|
547 |
| |
|
548 |
| |
|
549 |
0
| public ICacheGroupsProvider getCacheGroupsProvider() {
|
|
550 |
0
| return cacheGroupsProvider;
|
|
551 |
| } |
|
552 |
| |
|
553 |
| |
|
554 |
| |
|
555 |
| |
|
556 |
| |
|
557 |
| |
|
558 |
| |
|
559 |
| |
|
560 |
| |
|
561 |
0
| public void setCacheGroupsProvider(ICacheGroupsProvider cacheGroupsProvider) {
|
|
562 |
0
| if (cacheGroupsProvider == null) throw new IllegalArgumentException("The ICacheGroupsProvider is null.");
|
|
563 |
0
| this.cacheGroupsProvider = cacheGroupsProvider;
|
|
564 |
| } |
|
565 |
| |
|
566 |
| |
|
567 |
| |
|
568 |
| |
|
569 |
| |
|
570 |
0
| public ICacheKeyProvider getCacheKeyProvider() {
|
|
571 |
0
| return cacheKeyProvider;
|
|
572 |
| } |
|
573 |
| |
|
574 |
| |
|
575 |
| |
|
576 |
| |
|
577 |
| |
|
578 |
| |
|
579 |
| |
|
580 |
| |
|
581 |
| |
|
582 |
0
| public void setCacheKeyProvider(ICacheKeyProvider cacheKeyProvider) {
|
|
583 |
0
| if (cacheKeyProvider == null) throw new IllegalArgumentException("The ICacheKeyProvider is null.");
|
|
584 |
0
| this.cacheKeyProvider = cacheKeyProvider;
|
|
585 |
| } |
|
586 |
| |
|
587 |
| |
|
588 |
| |
|
589 |
| |
|
590 |
| |
|
591 |
| |
|
592 |
0
| public int getCacheScope() {
|
|
593 |
0
| return cacheScope;
|
|
594 |
| } |
|
595 |
| |
|
596 |
| |
|
597 |
| |
|
598 |
| |
|
599 |
| |
|
600 |
| |
|
601 |
| |
|
602 |
| |
|
603 |
0
| public void setCacheScope(int cacheScope) {
|
|
604 |
0
| if ((cacheScope != PageContext.APPLICATION_SCOPE) && (cacheScope != PageContext.SESSION_SCOPE))
|
|
605 |
0
| throw new IllegalArgumentException("Acceptable values for cache scope are PageContext.APPLICATION_SCOPE or PageContext.SESSION_SCOPE");
|
|
606 |
0
| this.cacheScope = cacheScope;
|
|
607 |
| } |
|
608 |
| |
|
609 |
| |
|
610 |
| |
|
611 |
| |
|
612 |
| |
|
613 |
0
| public String getCron() {
|
|
614 |
0
| return cron;
|
|
615 |
| } |
|
616 |
| |
|
617 |
| |
|
618 |
| |
|
619 |
| |
|
620 |
| |
|
621 |
| |
|
622 |
| |
|
623 |
| |
|
624 |
| |
|
625 |
0
| public void setCron(String cron) {
|
|
626 |
0
| this.cron = cron;
|
|
627 |
| } |
|
628 |
| |
|
629 |
| |
|
630 |
| |
|
631 |
| |
|
632 |
| |
|
633 |
0
| public long getExpires() {
|
|
634 |
0
| return expires;
|
|
635 |
| } |
|
636 |
| |
|
637 |
| |
|
638 |
| |
|
639 |
| |
|
640 |
| |
|
641 |
| |
|
642 |
| |
|
643 |
| |
|
644 |
| |
|
645 |
| |
|
646 |
0
| public void setExpires(long expires) {
|
|
647 |
0
| if ((expires < EXPIRES_TIME) || (expires > EXPIRES_ON)) throw new IllegalArgumentException("Expires value out of range.");
|
|
648 |
0
| this.expires = expires;
|
|
649 |
| } |
|
650 |
| |
|
651 |
| |
|
652 |
| |
|
653 |
| |
|
654 |
| |
|
655 |
0
| public EntryRefreshPolicy getExpiresRefreshPolicy() {
|
|
656 |
0
| return expiresRefreshPolicy;
|
|
657 |
| } |
|
658 |
| |
|
659 |
| |
|
660 |
| |
|
661 |
| |
|
662 |
| |
|
663 |
| |
|
664 |
| |
|
665 |
| |
|
666 |
| |
|
667 |
0
| public void setExpiresRefreshPolicy(EntryRefreshPolicy expiresRefreshPolicy) {
|
|
668 |
0
| if (expiresRefreshPolicy == null) throw new IllegalArgumentException("The EntryRefreshPolicy is null.");
|
|
669 |
0
| this.expiresRefreshPolicy = expiresRefreshPolicy;
|
|
670 |
| } |
|
671 |
| |
|
672 |
| |
|
673 |
| |
|
674 |
| |
|
675 |
| |
|
676 |
0
| public int getFragment() {
|
|
677 |
0
| return fragment;
|
|
678 |
| } |
|
679 |
| |
|
680 |
| |
|
681 |
| |
|
682 |
| |
|
683 |
| |
|
684 |
| |
|
685 |
| |
|
686 |
| |
|
687 |
0
| public void setFragment(int fragment) {
|
|
688 |
0
| if ((fragment < FRAGMENT_AUTODETECT) || (fragment > FRAGMENT_YES)) throw new IllegalArgumentException("Fragment value out of range.");
|
|
689 |
0
| this.fragment = fragment;
|
|
690 |
| } |
|
691 |
| |
|
692 |
| |
|
693 |
| |
|
694 |
| |
|
695 |
| |
|
696 |
0
| public long getLastModified() {
|
|
697 |
0
| return lastModified;
|
|
698 |
| } |
|
699 |
| |
|
700 |
| |
|
701 |
| |
|
702 |
| |
|
703 |
| |
|
704 |
| |
|
705 |
| |
|
706 |
| |
|
707 |
| |
|
708 |
| |
|
709 |
0
| public void setLastModified(long lastModified) {
|
|
710 |
0
| if ((lastModified < LAST_MODIFIED_INITIAL) || (lastModified > LAST_MODIFIED_ON)) throw new IllegalArgumentException("LastModified value out of range.");
|
|
711 |
0
| this.lastModified = lastModified;
|
|
712 |
| } |
|
713 |
| |
|
714 |
| |
|
715 |
| |
|
716 |
| |
|
717 |
| |
|
718 |
0
| public int getNocache() {
|
|
719 |
0
| return nocache;
|
|
720 |
| } |
|
721 |
| |
|
722 |
| |
|
723 |
| |
|
724 |
| |
|
725 |
| |
|
726 |
| |
|
727 |
| |
|
728 |
| |
|
729 |
| |
|
730 |
0
| public void setNocache(int nocache) {
|
|
731 |
0
| if ((nocache < NOCACHE_OFF) || (nocache > NOCACHE_SESSION_ID_IN_URL)) throw new IllegalArgumentException("Nocache value out of range.");
|
|
732 |
0
| this.nocache = nocache;
|
|
733 |
| } |
|
734 |
| |
|
735 |
| |
|
736 |
| |
|
737 |
| |
|
738 |
| |
|
739 |
0
| public int getTime() {
|
|
740 |
0
| return time;
|
|
741 |
| } |
|
742 |
| |
|
743 |
| |
|
744 |
| |
|
745 |
| |
|
746 |
| |
|
747 |
| |
|
748 |
| |
|
749 |
| |
|
750 |
| |
|
751 |
| |
|
752 |
0
| public void setTime(int time) {
|
|
753 |
0
| this.time = time;
|
|
754 |
| |
|
755 |
0
| if (expiresRefreshPolicy instanceof ExpiresRefreshPolicy) {
|
|
756 |
0
| ((ExpiresRefreshPolicy) expiresRefreshPolicy).setRefreshPeriod(time);
|
|
757 |
| } |
|
758 |
| } |
|
759 |
| |
|
760 |
| |
|
761 |
| |
|
762 |
| |
|
763 |
| |
|
764 |
| |
|
765 |
0
| public List getDisableCacheOnMethods() {
|
|
766 |
0
| return disableCacheOnMethods;
|
|
767 |
| } |
|
768 |
| |
|
769 |
| |
|
770 |
| |
|
771 |
| |
|
772 |
| |
|
773 |
| |
|
774 |
| |
|
775 |
| |
|
776 |
0
| public void setDisableCacheOnMethods(List disableCacheOnMethods) {
|
|
777 |
0
| this.disableCacheOnMethods = disableCacheOnMethods;
|
|
778 |
| } |
|
779 |
| |
|
780 |
| |
|
781 |
| |
|
782 |
| } |