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.BasePortalCache;
18  
19  import java.io.Serializable;
20  
21  import java.util.ArrayList;
22  import java.util.Collection;
23  import java.util.List;
24  import java.util.Map;
25  import java.util.concurrent.ConcurrentHashMap;
26  
27  /**
28   * <a href="MemoryPortalCache.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Brian Wing Shun Chan
31   */
32  public class MemoryPortalCache extends BasePortalCache {
33  
34      public MemoryPortalCache(int initialCapacity) {
35           _map = new ConcurrentHashMap<String, Object>(initialCapacity);
36      }
37  
38      public Collection<Object> get(Collection<String> keys) {
39          List<Object> values = new ArrayList<Object>(keys.size());
40  
41          for (String key : keys) {
42              values.add(get(key));
43          }
44  
45          return values;
46      }
47  
48      public Object get(String key) {
49          String processedKey = processKey(key);
50  
51          return _map.get(processedKey);
52      }
53  
54      public void put(String key, Object obj) {
55          String processedKey = processKey(key);
56  
57          _map.put(processedKey, obj);
58      }
59  
60      public void put(String key, Object obj, int timeToLive) {
61          String processedKey = processKey(key);
62  
63          _map.put(processedKey, obj);
64      }
65  
66      public void put(String key, Serializable obj) {
67          String processedKey = processKey(key);
68  
69          _map.put(processedKey, obj);
70      }
71  
72      public void put(String key, Serializable obj, int timeToLive) {
73          String processedKey = processKey(key);
74  
75          _map.put(processedKey, obj);
76      }
77  
78      public void remove(String key) {
79          String processedKey = processKey(key);
80  
81          _map.remove(processedKey);
82      }
83  
84      public void removeAll() {
85          _map.clear();
86      }
87  
88      private Map<String, Object> _map;
89  
90  }