1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.core.impl.cache;
17
18 import org.kuali.rice.core.api.cache.CacheService;
19 import org.kuali.rice.core.api.cache.CacheTarget;
20 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
21 import org.springframework.beans.factory.InitializingBean;
22 import org.springframework.cache.Cache;
23 import org.springframework.cache.CacheManager;
24
25 import java.util.Collection;
26
27 public class CacheServiceImpl implements CacheService, InitializingBean {
28
29 private CacheManager cacheManager;
30
31 @Override
32 public void flush(Collection<CacheTarget> cacheTargets) throws RiceIllegalArgumentException {
33 if (cacheTargets == null) {
34 throw new RiceIllegalArgumentException("cacheTargets is null");
35 }
36 for (CacheTarget cacheTarget : cacheTargets) {
37 if (cacheTarget == null) {
38 throw new RiceIllegalArgumentException("cacheTarget is null");
39 }
40 final Cache c = getCache(cacheTarget.getCache());
41 if (c != null) {
42 if (cacheTarget.containsKey()) {
43 c.evict(cacheTarget.getKey());
44 } else {
45 c.clear();
46 }
47 }
48 }
49 }
50
51 private Cache getCache(String cache) {
52 return cacheManager.getCache(cache);
53 }
54
55 public void setCacheManager(CacheManager cacheManager) {
56 this.cacheManager = cacheManager;
57 }
58
59 @Override
60 public void afterPropertiesSet() throws Exception {
61 if (cacheManager == null) {
62 throw new IllegalStateException("the cacheManager must be set");
63 }
64 }
65 }