1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.module.cache.ehcache3; |
35 |
|
|
36 |
|
import info.magnolia.module.cache.BlockingCache; |
37 |
|
import info.magnolia.module.cache.CacheModule; |
38 |
|
import info.magnolia.module.cache.blocking.AbstractBlockingCache; |
39 |
|
import info.magnolia.module.cache.filter.CachedEntry; |
40 |
|
|
41 |
|
import java.io.IOException; |
42 |
|
import java.util.ArrayList; |
43 |
|
import java.util.Iterator; |
44 |
|
import java.util.List; |
45 |
|
|
46 |
|
import javax.servlet.FilterChain; |
47 |
|
import javax.servlet.ServletException; |
48 |
|
import javax.servlet.http.HttpServletRequest; |
49 |
|
import javax.servlet.http.HttpServletResponse; |
50 |
|
|
51 |
|
import org.ehcache.Cache; |
52 |
|
import org.ehcache.Status; |
53 |
|
import org.ehcache.UserManagedCache; |
54 |
|
import org.slf4j.Logger; |
55 |
|
import org.slf4j.LoggerFactory; |
56 |
|
|
57 |
|
|
58 |
|
|
59 |
|
|
|
|
| 34.3% |
Uncovered Elements: 44 (67) |
Complexity: 21 |
Complexity Density: 0.57 |
|
60 |
|
public class EhCache3Wrapper extends AbstractBlockingCache implements BlockingCache { |
61 |
|
|
62 |
|
private static final Logger log = LoggerFactory.getLogger(EhCache3Wrapper.class); |
63 |
|
|
64 |
|
private final Cache ehcache; |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
66 |
4 |
public EhCache3Wrapper(String name, CacheModule cacheModule, int blockingTimeout, Cache ehcache) {... |
67 |
4 |
super(name, cacheModule, blockingTimeout); |
68 |
4 |
this.ehcache = ehcache; |
69 |
|
} |
70 |
|
|
|
|
| 77.8% |
Uncovered Elements: 2 (9) |
Complexity: 3 |
Complexity Density: 0.6 |
|
71 |
5 |
@Override... |
72 |
|
public Object getQuiet(Object key) { |
73 |
5 |
if (isInitialized()) { |
74 |
5 |
super.getQuiet(key); |
75 |
5 |
final Object value = ehcache.get(key); |
76 |
5 |
return value instanceof CacheEntryTtlWrapper ? ((CacheEntryTtlWrapper) value).getWrappedValue() : value; |
77 |
|
} else { |
78 |
0 |
return null; |
79 |
|
} |
80 |
|
} |
81 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 4 |
Complexity Density: 1 |
|
82 |
3 |
@Override... |
83 |
|
protected void putQuiet(Object key, Object value, int timeToLiveInSeconds) { |
84 |
3 |
if (isInitialized()) { |
85 |
3 |
if (timeToLiveInSeconds != -1 && !(value instanceof CachedEntry)) { |
86 |
1 |
value = new CacheEntryTtlWrapper(value, timeToLiveInSeconds); |
87 |
|
} |
88 |
3 |
ehcache.put(key, value); |
89 |
|
} |
90 |
|
} |
91 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.75 |
|
92 |
|
private static class CacheEntryTtlWrapper implements CachedEntry { |
93 |
|
|
94 |
|
final Object wrapped; |
95 |
|
final int ttl; |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
97 |
1 |
private CacheEntryTtlWrapper(Object wrapped, int ttl) {... |
98 |
1 |
this.wrapped = wrapped; |
99 |
1 |
this.ttl = ttl; |
100 |
|
} |
101 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
102 |
0 |
@Override... |
103 |
|
public void replay(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { |
104 |
0 |
throw new UnsupportedOperationException(); |
105 |
|
} |
106 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
107 |
|
@Override... |
108 |
|
public String getOriginalURL() { |
109 |
|
throw new UnsupportedOperationException(); |
110 |
|
} |
111 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
112 |
|
@Override... |
113 |
|
public long getLastModificationTime() { |
114 |
|
throw new UnsupportedOperationException(); |
115 |
|
} |
116 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
117 |
|
@Override... |
118 |
|
public int getTimeToLiveInSeconds() { |
119 |
|
return ttl; |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
122 |
1 |
private Object getWrappedValue() {... |
123 |
1 |
return wrapped; |
124 |
|
} |
125 |
|
} |
126 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
127 |
0 |
@Override... |
128 |
|
public void remove(Object key) { |
129 |
0 |
if (isInitialized()) { |
130 |
0 |
ehcache.remove(key); |
131 |
0 |
super.remove(key); |
132 |
|
} |
133 |
|
} |
134 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
135 |
0 |
@Override... |
136 |
|
public void clear() { |
137 |
0 |
if (isInitialized()) { |
138 |
0 |
ehcache.clear(); |
139 |
0 |
super.clear(); |
140 |
|
} |
141 |
|
} |
142 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
143 |
0 |
@Override... |
144 |
|
public int getSize() { |
145 |
0 |
if (!isInitialized()) { |
146 |
0 |
return 0; |
147 |
|
} |
148 |
0 |
final Iterator iterator = ehcache.iterator(); |
149 |
0 |
int size = 0; |
150 |
0 |
while(iterator.hasNext()) { |
151 |
0 |
iterator.next(); |
152 |
0 |
size++; |
153 |
|
} |
154 |
0 |
return size; |
155 |
|
} |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
157 |
0 |
@Override... |
158 |
|
public List<Object> getKeys() { |
159 |
0 |
if (!isInitialized()) { |
160 |
0 |
return new ArrayList<>(); |
161 |
|
} |
162 |
0 |
final Iterator<Cache.Entry> iterator = ehcache.iterator(); |
163 |
0 |
final List<Object> keys = new ArrayList<>(); |
164 |
0 |
while(iterator.hasNext()) { |
165 |
0 |
Cache.Entry entry = iterator.next(); |
166 |
0 |
keys.add(entry.getKey()); |
167 |
|
} |
168 |
0 |
return keys; |
169 |
|
} |
170 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
171 |
|
public Cache getWrappedEhCache() {... |
172 |
|
return ehcache; |
173 |
|
} |
174 |
|
|
|
|
| 50% |
Uncovered Elements: 3 (6) |
Complexity: 3 |
Complexity Density: 0.75 |
|
175 |
8 |
private boolean isInitialized() {... |
176 |
8 |
if (ehcache instanceof UserManagedCache && ((UserManagedCache) ehcache).getStatus() == Status.UNINITIALIZED) { |
177 |
0 |
log.warn("Cache named {{}} is {}. Ignoring any calls on it. This might happen when editing the Ehcache factory configuration at runtime", getName(), Status.UNINITIALIZED); |
178 |
0 |
return false; |
179 |
|
} else { |
180 |
8 |
return true; |
181 |
|
} |
182 |
|
} |
183 |
|
} |