View Javadoc
1   /*
2    * Copyright 2009 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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   * @see org.kuali.ole.sys.batch.service.CacheService
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       * @see org.kuali.ole.sys.batch.service.CacheService#clearSystemCache()
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                  // this is at debug level intentionally, since not all BOs have caches
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  }