1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.sys.batch.service.impl;
17
18 import org.kuali.ole.sys.OLEConstants;
19 import org.kuali.ole.sys.batch.service.CacheService;
20 import org.kuali.ole.sys.service.NonTransactional;
21 import org.kuali.rice.core.impl.services.CoreImplServiceLocator;
22 import org.springframework.cache.Cache;
23 import org.springframework.cache.CacheManager;
24
25
26
27
28 @NonTransactional
29 public class CacheServiceImpl implements CacheService {
30 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CacheServiceImpl.class);
31
32
33
34
35 @Override
36 public void clearSystemCaches() {
37 for ( CacheManager cm : CoreImplServiceLocator.getCacheManagerRegistry().getCacheManagers() ) {
38 for ( String cacheName : cm.getCacheNames() ) {
39 cm.getCache(cacheName).clear();
40 }
41 }
42 }
43
44 @Override
45 public void clearNamedCache(String cacheName) {
46 CacheManager cm = CoreImplServiceLocator.getCacheManagerRegistry().getCacheManager(
47 OLEConstants.KFS_CORE_DISTRIBUTED_CACHE_MANAGER);
48 if (cm != null) {
49 Cache cache = cm.getCache(cacheName);
50 if (cache != null) {
51 cache.clear();
52 if (LOG.isDebugEnabled()) {
53 LOG.debug("Cleared " + cacheName + " cache in cache manager "
54 + OLEConstants.KFS_CORE_DISTRIBUTED_CACHE_MANAGER + ".");
55 }
56 }
57 else {
58
59 LOG.debug("Unable to find cache for " + cacheName + " in cache manager "
60 + OLEConstants.KFS_CORE_DISTRIBUTED_CACHE_MANAGER);
61 }
62 }
63 else {
64 LOG.info("Unable to find cache manager " + OLEConstants.KFS_CORE_DISTRIBUTED_CACHE_MANAGER
65 + " when attempting to clear " + cacheName);
66 }
67 }
68
69 @Override
70 public void clearKfsBusinessObjectCache(Class boClass) {
71 String cacheName = OLEConstants.APPLICATION_NAMESPACE_CODE + "/" + boClass.getSimpleName();
72 clearNamedCache(cacheName);
73 }
74 }