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;
35
36 import info.magnolia.module.cache.executor.Bypass;
37
38 import java.util.HashMap;
39 import java.util.Map;
40
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44
45
46
47
48
49
50
51
52
53
54 public class CacheConfiguration {
55
56 private static Logger log = LoggerFactory.getLogger(CacheConfiguration.class);
57
58 private String name;
59 private CachePolicy cachePolicy;
60 private FlushPolicy flushPolicy;
61 private BrowserCachePolicy browserCachePolicy;
62
63 private Map<String, CachePolicyExecutor> executors = new HashMap<String, CachePolicyExecutor>();
64
65 public CacheConfiguration() {
66 }
67
68
69
70
71 CacheConfiguration(String name, CachePolicy cachePolicy, FlushPolicy flushPolicy) {
72 this.name = name;
73 this.cachePolicy = cachePolicy;
74 this.flushPolicy = flushPolicy;
75 }
76
77 public String getName() {
78 return name;
79 }
80
81 public void setName(String name) {
82 this.name = name;
83 }
84
85 public CachePolicy getCachePolicy() {
86 if (cachePolicy != null) {
87 return cachePolicy;
88 }
89
90 log.error("Check your cache configuration! CachePolicy is probably not set! Falling back Never cache policy.");
91 return new info.magnolia.module.cache.cachepolicy.Never();
92 }
93
94 public void setCachePolicy(CachePolicy cachePolicy) {
95 this.cachePolicy = cachePolicy;
96 }
97
98 public FlushPolicy getFlushPolicy() {
99 if (flushPolicy != null) {
100 return flushPolicy;
101 }
102
103 log.error("Check your cache configuration! FlushPolicy is probably not set! Falling back to FlushAllListeningPolicy.");
104 return new FlushAllListeningPolicy();
105 }
106
107 public void setFlushPolicy(FlushPolicy flushPolicy) {
108 this.flushPolicy = flushPolicy;
109 }
110
111 public CachePolicyExecutor getExecutor(CachePolicyResult.CachePolicyBehaviour behaviour) {
112 if (executors.containsKey(behaviour.getName())) {
113 return executors.get(behaviour.getName());
114 }
115
116 log.error("Check your cache configuration! Executor " + behaviour.getName() + " is probably not set! Bypassing cache.");
117 return new Bypass();
118 }
119
120 public BrowserCachePolicy getBrowserCachePolicy() {
121 if (browserCachePolicy != null) {
122 return browserCachePolicy;
123 }
124
125 log.error("Check your cache configuration! BrowserCachePolicy is probably not set! Falling back to Never cache policy.");
126 return new info.magnolia.module.cache.browsercachepolicy.Never();
127 }
128
129 public void setBrowserCachePolicy(BrowserCachePolicy browserCachePolicy) {
130 this.browserCachePolicy = browserCachePolicy;
131 }
132
133 public Map<String, CachePolicyExecutor> getExecutors() {
134 return executors;
135 }
136
137 public void setExecutors(Map<String, CachePolicyExecutor> executors) {
138 this.executors = executors;
139 }
140
141 public void addExecutor(String name, CachePolicyExecutor executor) {
142 executor.setCacheConfiguration(this);
143 this.executors.put(name, executor);
144 }
145
146 }