|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| package com.opensymphony.oscache.web; |
|
6 |
| |
|
7 |
| import com.opensymphony.oscache.base.Cache; |
|
8 |
| import com.opensymphony.oscache.base.CacheEntry; |
|
9 |
| |
|
10 |
| import org.apache.commons.logging.Log; |
|
11 |
| import org.apache.commons.logging.LogFactory; |
|
12 |
| |
|
13 |
| import java.io.Serializable; |
|
14 |
| |
|
15 |
| import javax.servlet.http.HttpSessionBindingEvent; |
|
16 |
| import javax.servlet.http.HttpSessionBindingListener; |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| public final class ServletCache extends Cache implements HttpSessionBindingListener, Serializable { |
|
28 |
| private static transient final Log log = LogFactory.getLog(ServletCache.class); |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| private ServletCacheAdministrator admin; |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| |
|
38 |
| private int scope; |
|
39 |
| |
|
40 |
| |
|
41 |
| |
|
42 |
| |
|
43 |
| |
|
44 |
| |
|
45 |
| |
|
46 |
0
| public ServletCache(ServletCacheAdministrator admin, int scope) {
|
|
47 |
0
| super(admin.isMemoryCaching(), admin.isUnlimitedDiskCache(), admin.isOverflowPersistence());
|
|
48 |
0
| setScope(scope);
|
|
49 |
0
| this.admin = admin;
|
|
50 |
| } |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
0
| public ServletCache(ServletCacheAdministrator admin, String algorithmClass, int limit, int scope) {
|
|
61 |
0
| super(admin.isMemoryCaching(), admin.isUnlimitedDiskCache(), admin.isOverflowPersistence(), admin.isBlocking(), algorithmClass, limit);
|
|
62 |
0
| setScope(scope);
|
|
63 |
0
| this.admin = admin;
|
|
64 |
| } |
|
65 |
| |
|
66 |
| |
|
67 |
| |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
0
| public int getScope() {
|
|
72 |
0
| return scope;
|
|
73 |
| } |
|
74 |
| |
|
75 |
0
| private void setScope(int scope) {
|
|
76 |
0
| this.scope = scope;
|
|
77 |
| } |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
| |
|
84 |
0
| public void valueBound(HttpSessionBindingEvent event) {
|
|
85 |
| } |
|
86 |
| |
|
87 |
| |
|
88 |
| |
|
89 |
| |
|
90 |
| |
|
91 |
| |
|
92 |
| |
|
93 |
0
| public void valueUnbound(HttpSessionBindingEvent event) {
|
|
94 |
0
| if (log.isInfoEnabled()) {
|
|
95 |
| |
|
96 |
0
| log.info("[Cache] Unbound from session " + event.getSession() + " using name " + event.getName());
|
|
97 |
| } |
|
98 |
| |
|
99 |
0
| admin.finalizeListeners(this);
|
|
100 |
0
| clear();
|
|
101 |
| } |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
| |
|
106 |
| |
|
107 |
| |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
| |
|
113 |
| |
|
114 |
| |
|
115 |
0
| protected boolean isStale(CacheEntry cacheEntry, int refreshPeriod, String cronExpiry) {
|
|
116 |
0
| return super.isStale(cacheEntry, refreshPeriod, cronExpiry) || admin.isScopeFlushed(cacheEntry, scope);
|
|
117 |
| } |
|
118 |
| } |