1
22
23 package com.liferay.portal.cache;
24
25 import com.liferay.portal.kernel.cache.MultiVMPool;
26 import com.liferay.portal.kernel.cache.PortalCache;
27 import com.liferay.portal.kernel.cache.PortalCacheManager;
28 import com.liferay.portal.kernel.util.ConcurrentHashSet;
29
30 import java.io.Serializable;
31
32 import java.util.Map;
33 import java.util.Set;
34
35
42 public class MultiVMPoolImpl implements MultiVMPool {
43
44 public void clear() {
45 _portalCacheManager.clearAll();
46 }
47
48 public void clear(String name) {
49 PortalCache portalCache = getCache(name);
50
51 portalCache.removeAll();
52 }
53
54 public void clearGroup(
55 Map<String, Set<String>> groups, String groupKey,
56 PortalCache portalCache) {
57
58 synchronized (groups) {
59 if (!groups.containsKey(groupKey)) {
60 return;
61 }
62
63 Set<String> groupKeys = groups.get(groupKey);
64
65 String[] keys = groupKeys.toArray(new String[groupKeys.size()]);
66
67 for (int i = 0; i < keys.length; i++) {
68 String key = keys[i];
69
70
75 portalCache.remove(key);
76 }
77
78 groupKeys.clear();
79 }
80 }
81
82 public Object get(String name, String key) {
83 PortalCache portalCache = getCache(name);
84
85 return get(portalCache, key);
86 }
87
88 public Object get(PortalCache portalCache, String key) {
89 return portalCache.get(key);
90 }
91
92 public PortalCache getCache(String name) {
93 return _portalCacheManager.getCache(name);
94 }
95
96 public void put(String name, String key, Object obj) {
97 PortalCache portalCache = getCache(name);
98
99 put(portalCache, key, obj);
100 }
101
102 public void put(PortalCache portalCache, String key, Object obj) {
103 portalCache.put(key, obj);
104 }
105
106 public void put(
107 PortalCache portalCache, String key, Map<String, Set<String>> groups,
108 String groupKey, Object obj) {
109
110 put(portalCache, key, obj);
111
112 updateGroup(groups, groupKey, key);
113 }
114
115 public void put(String name, String key, Serializable obj) {
116 PortalCache portalCache = getCache(name);
117
118 put(portalCache, key, obj);
119 }
120
121 public void put(PortalCache portalCache, String key, Serializable obj) {
122 portalCache.put(key, obj);
123 }
124
125 public void put(
126 PortalCache portalCache, String key, Map<String, Set<String>> groups,
127 String groupKey, Serializable obj) {
128
129 put(portalCache, key, obj);
130
131 updateGroup(groups, groupKey, key);
132 }
133
134 public void remove(String name, String key) {
135 PortalCache portalCache = getCache(name);
136
137 remove(portalCache, key);
138 }
139
140 public void remove(PortalCache portalCache, String key) {
141 portalCache.remove(key);
142 }
143
144 public void setPortalCacheManager(PortalCacheManager portalCacheManager) {
145 _portalCacheManager = portalCacheManager;
146 }
147
148 public void updateGroup(
149 Map<String, Set<String>> groups, String groupKey, String key) {
150
151 synchronized (groups) {
152 Set<String> groupKeys = null;
153
154 if (groups.containsKey(groupKey)) {
155 groupKeys = groups.get(groupKey);
156 }
157 else {
158 groupKeys = new ConcurrentHashSet<String>();
159
160 groups.put(groupKey, groupKeys);
161 }
162
163 groupKeys.add(key);
164 }
165 }
166
167 private PortalCacheManager _portalCacheManager;
168
169 }