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.util.CollectionFactory;
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 groups, String groupKey, PortalCache portalCache) {
56
57 if (!groups.containsKey(groupKey)) {
58 return;
59 }
60
61 Set groupKeys = (Set)groups.get(groupKey);
62
63 String[] keys = (String[])groupKeys.toArray(new String[0]);
64
65 for (int i = 0; i < keys.length; i++) {
66 String key = keys[i];
67
68
73 portalCache.remove(key);
74 }
75
76 groupKeys.clear();
77 }
78
79 public Object get(String name, String key) {
80 PortalCache portalCache = getCache(name);
81
82 return get(portalCache, key);
83 }
84
85 public Object get(PortalCache portalCache, String key) {
86 return portalCache.get(key);
87 }
88
89 public PortalCache getCache(String name) {
90 return _portalCacheManager.getCache(name);
91 }
92
93 public void put(String name, String key, Object obj) {
94 PortalCache portalCache = getCache(name);
95
96 put(portalCache, key, obj);
97 }
98
99 public void put(PortalCache portalCache, String key, Object obj) {
100 portalCache.put(key, obj);
101 }
102
103 public void put(
104 PortalCache portalCache, String key, Map groups, String groupKey,
105 Object obj) {
106
107 put(portalCache, key, obj);
108
109 updateGroup(groups, groupKey, key);
110 }
111
112 public void put(String name, String key, Serializable obj) {
113 PortalCache portalCache = getCache(name);
114
115 put(portalCache, key, obj);
116 }
117
118 public void put(PortalCache portalCache, String key, Serializable obj) {
119 portalCache.put(key, obj);
120 }
121
122 public void put(
123 PortalCache portalCache, String key, Map groups, String groupKey,
124 Serializable obj) {
125
126 put(portalCache, key, obj);
127
128 updateGroup(groups, groupKey, key);
129 }
130
131 public void remove(String name, String key) {
132 PortalCache portalCache = getCache(name);
133
134 remove(portalCache, key);
135 }
136
137 public void remove(PortalCache portalCache, String key) {
138 portalCache.remove(key);
139 }
140
141 public void setPortalCacheManager(PortalCacheManager portalCacheManager) {
142 _portalCacheManager = portalCacheManager;
143 }
144
145 public void updateGroup(Map groups, String groupKey, String key) {
146 Set groupKeys = null;
147
148 if (groups.containsKey(groupKey)) {
149 groupKeys = (Set)groups.get(groupKey);
150 }
151 else {
152 groupKeys = CollectionFactory.getSyncHashSet();
153
154 groups.put(groupKey, groupKeys);
155 }
156
157 groupKeys.add(key);
158 }
159
160 private PortalCacheManager _portalCacheManager;
161
162 }