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 | 0 | public class CacheServiceImpl implements CacheService, InitializingBean { |
28 | |
|
29 | |
private CacheManager cacheManager; |
30 | |
|
31 | |
@Override |
32 | |
public void flush(Collection<CacheTarget> cacheTargets) throws RiceIllegalArgumentException { |
33 | 0 | if (cacheTargets == null) { |
34 | 0 | throw new RiceIllegalArgumentException("cacheTargets is null"); |
35 | |
} |
36 | 0 | for (CacheTarget cacheTarget : cacheTargets) { |
37 | 0 | if (cacheTarget == null) { |
38 | 0 | throw new RiceIllegalArgumentException("cacheTarget is null"); |
39 | |
} |
40 | 0 | final Cache c = getCache(cacheTarget.getCache()); |
41 | 0 | if (c != null) { |
42 | 0 | if (cacheTarget.containsKey()) { |
43 | 0 | c.evict(cacheTarget.getKey()); |
44 | |
} else { |
45 | 0 | c.clear(); |
46 | |
} |
47 | |
} |
48 | 0 | } |
49 | 0 | } |
50 | |
|
51 | |
private Cache getCache(String cache) { |
52 | 0 | return cacheManager.getCache(cache); |
53 | |
} |
54 | |
|
55 | |
public void setCacheManager(CacheManager cacheManager) { |
56 | 0 | this.cacheManager = cacheManager; |
57 | 0 | } |
58 | |
|
59 | |
@Override |
60 | |
public void afterPropertiesSet() throws Exception { |
61 | 0 | if (cacheManager == null) { |
62 | 0 | throw new IllegalStateException("the cacheManager must be set"); |
63 | |
} |
64 | 0 | } |
65 | |
} |