1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.cache.memory;
16  
17  import com.liferay.portal.kernel.cache.PortalCache;
18  import com.liferay.portal.kernel.cache.PortalCacheManager;
19  
20  import java.util.Map;
21  import java.util.concurrent.ConcurrentHashMap;
22  
23  /**
24   * <a href="MemoryPortalCacheManager.java.html"><b><i>View Source</i></b></a>
25   *
26   * @author Brian Wing Shun Chan
27   */
28  public class MemoryPortalCacheManager implements PortalCacheManager {
29  
30      public void afterPropertiesSet() {
31          _portalCaches = new ConcurrentHashMap<String, PortalCache>(
32              _cacheManagerInitialCapacity);
33      }
34  
35      public void clearAll() {
36          _portalCaches.clear();
37      }
38  
39      public PortalCache getCache(String name) {
40          return getCache(name, false);
41      }
42  
43      public PortalCache getCache(String name, boolean blocking) {
44          PortalCache portalCache = _portalCaches.get(name);
45  
46          if (portalCache == null) {
47              portalCache = new MemoryPortalCache(_cacheInitialCapacity);
48  
49              portalCache.setDebug(_debug);
50  
51              _portalCaches.put(name, portalCache);
52          }
53  
54          return portalCache;
55      }
56  
57      public void removeCache(String name) {
58          _portalCaches.remove(name);
59      }
60  
61      public void setCacheInitialCapacity(int cacheInitialCapacity) {
62          _cacheInitialCapacity = cacheInitialCapacity;
63      }
64  
65      public void setCacheManagerInitialCapacity(
66          int cacheManagerInitialCapacity) {
67  
68          _cacheManagerInitialCapacity = cacheManagerInitialCapacity;
69      }
70  
71      public void setDebug(boolean debug) {
72          _debug = debug;
73      }
74  
75      private int _cacheInitialCapacity = 10000;
76      private int _cacheManagerInitialCapacity = 10000;
77      private boolean _debug;
78      private Map<String, PortalCache> _portalCaches;
79  
80  }