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          _cacheMap = new ConcurrentHashMap<String, PortalCache>(
32              _cacheManagerInitialCapacity);
33      }
34  
35      public void clearAll() {
36          _cacheMap.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 cache = _cacheMap.get(name);
45  
46          if (cache == null) {
47              cache = new MemoryPortalCache(_cacheInitialCapacity);
48  
49              _cacheMap.put(name, cache);
50          }
51  
52          return cache;
53      }
54  
55      public void setCacheInitialCapacity(int cacheInitialCapacity) {
56          _cacheInitialCapacity = cacheInitialCapacity;
57      }
58  
59      public void setCacheManagerInitialCapacity(
60          int cacheManagerInitialCapacity) {
61  
62          _cacheManagerInitialCapacity = cacheManagerInitialCapacity;
63      }
64  
65      private int _cacheInitialCapacity = 10000;
66      private int _cacheManagerInitialCapacity = 10000;
67      private Map<String, PortalCache> _cacheMap;
68  
69  }