1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
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 setCacheInitialCapacity(int cacheInitialCapacity) {
58          _cacheInitialCapacity = cacheInitialCapacity;
59      }
60  
61      public void setCacheManagerInitialCapacity(
62          int cacheManagerInitialCapacity) {
63  
64          _cacheManagerInitialCapacity = cacheManagerInitialCapacity;
65      }
66  
67      public void setDebug(boolean debug) {
68          _debug = debug;
69      }
70  
71      private int _cacheInitialCapacity = 10000;
72      private int _cacheManagerInitialCapacity = 10000;
73      private boolean _debug;
74      private Map<String, PortalCache> _portalCaches;
75  
76  }