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.commands; |
35 |
|
|
36 |
|
import info.magnolia.commands.MgnlCommand; |
37 |
|
import info.magnolia.context.Context; |
38 |
|
import info.magnolia.module.cache.Cache; |
39 |
|
import info.magnolia.module.cache.CacheFactory; |
40 |
|
import info.magnolia.module.cache.CacheModule; |
41 |
|
import info.magnolia.module.cache.CachePolicy; |
42 |
|
import info.magnolia.module.cache.ContentCachingConfiguration; |
43 |
|
import info.magnolia.module.cache.cachepolicy.Never; |
44 |
|
import info.magnolia.objectfactory.Components; |
45 |
|
|
46 |
|
import java.util.Arrays; |
47 |
|
import java.util.Collection; |
48 |
|
import java.util.HashSet; |
49 |
|
import java.util.Set; |
50 |
|
|
51 |
|
import javax.inject.Inject; |
52 |
|
|
53 |
|
import org.apache.commons.lang3.StringUtils; |
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
|
|
| 65.5% |
Uncovered Elements: 10 (29) |
Complexity: 6 |
Complexity Density: 0.3 |
|
58 |
|
public class FlushFromCachesByUUIDCommand extends MgnlCommand { |
59 |
|
|
60 |
|
public static final String WORKSPACE = "repository"; |
61 |
|
public static final String UUID = "uuid"; |
62 |
|
|
63 |
|
private final CacheModule cacheModule; |
64 |
|
private String uuid; |
65 |
|
private String workspace; |
66 |
|
|
67 |
|
|
68 |
|
@deprecated@link |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0 |
@Deprecated... |
71 |
|
public FlushFromCachesByUUIDCommand() { |
72 |
0 |
this(Components.getComponent(CacheModule.class)); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
1 |
@Inject... |
76 |
|
public FlushFromCachesByUUIDCommand(CacheModule cacheModule) { |
77 |
1 |
this.cacheModule = cacheModule; |
78 |
|
} |
79 |
|
|
|
|
| 66.7% |
Uncovered Elements: 8 (24) |
Complexity: 4 |
Complexity Density: 0.22 |
|
80 |
1 |
@Override... |
81 |
|
public boolean execute(Context ctx) throws Exception { |
82 |
1 |
String uuid = (String) ctx.get(UUID); |
83 |
1 |
if (StringUtils.isBlank(uuid)) { |
84 |
1 |
uuid = getUuid(); |
85 |
|
} |
86 |
1 |
String workspace = (String) ctx.get(WORKSPACE); |
87 |
1 |
if (StringUtils.isBlank(workspace)) { |
88 |
1 |
workspace = getWorkspace(); |
89 |
|
} |
90 |
1 |
final Set<Object> keySet = new HashSet<Object>(); |
91 |
1 |
Collection<ContentCachingConfiguration> cacheConfigs = cacheModule.getContentCaching().values(); |
92 |
1 |
for (ContentCachingConfiguration config : cacheConfigs) { |
93 |
1 |
if (!(config.getCachePolicy() instanceof Never)) { |
94 |
0 |
CachePolicy policy = config.getCachePolicy(); |
95 |
0 |
keySet.addAll(Arrays.asList(policy.removeCacheKeys(uuid, workspace))); |
96 |
|
} |
97 |
|
} |
98 |
|
|
99 |
1 |
CacheFactory factory = cacheModule.getCacheFactory(); |
100 |
|
|
101 |
1 |
for (Object key : keySet) { |
102 |
0 |
for (ContentCachingConfiguration config : cacheConfigs) { |
103 |
0 |
final Cache cache = factory.getCache(config.getCacheName()); |
104 |
0 |
cache.remove(key); |
105 |
|
} |
106 |
|
} |
107 |
1 |
return true; |
108 |
|
} |
109 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
110 |
|
public String getUuid() {... |
111 |
|
return uuid; |
112 |
|
} |
113 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
114 |
|
public void setUuid(String uuid) {... |
115 |
|
this.uuid = uuid; |
116 |
|
} |
117 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
118 |
|
public String getWorkspace() {... |
119 |
|
return workspace; |
120 |
|
} |
121 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
122 |
|
public void setWorkspace(String workspace) {... |
123 |
|
this.workspace = workspace; |
124 |
|
} |
125 |
|
} |