View Javadoc

1   /**
2    * Copyright 2005-2015 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.rice.core.impl.cache;
17  
18  import org.kuali.rice.core.api.cache.CacheManagerRegistry;
19  import org.springframework.cache.Cache;
20  import org.springframework.cache.CacheManager;
21  
22  import java.util.ArrayList;
23  import java.util.Collection;
24  import java.util.Collections;
25  import java.util.List;
26  
27  public class GlobalCacheManager implements CacheManager {
28  
29  
30      private CacheManagerRegistry cacheManagerRegistry;
31  
32      @Override
33      public Cache getCache(String name) {
34          return cacheManagerRegistry.getCacheManagerByCacheName(name).getCache(name);
35      }
36  
37      @Override
38      public Collection<String> getCacheNames() {
39          List<String> cacheNames = new ArrayList<String>();
40          for (CacheManager cm : cacheManagerRegistry.getCacheManagers()) {
41              cacheNames.addAll(cm.getCacheNames());
42          }
43          return Collections.unmodifiableCollection(cacheNames);
44      }
45  
46      public void setCacheManagerRegistry(CacheManagerRegistry cacheManagerRegistry) {
47          this.cacheManagerRegistry = cacheManagerRegistry;
48      }
49  }