1
14
15 package com.liferay.portal.service.impl;
16
17 import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
18 import com.liferay.portal.kernel.cache.PortalCache;
19 import com.liferay.portal.kernel.util.StringBundler;
20 import com.liferay.portal.kernel.util.StringPool;
21 import com.liferay.portal.kernel.util.StringUtil;
22 import com.liferay.portlet.PortletPreferencesImpl;
23
24 import java.util.Map;
25 import java.util.concurrent.ConcurrentHashMap;
26
27
33 public class PortletPreferencesLocalUtil {
34
35 public static final String CACHE_NAME =
36 PortletPreferencesLocalUtil.class.getName();
37
38 protected static void clearPreferencesPool() {
39 _portalCache.removeAll();
40 }
41
42 protected static void clearPreferencesPool(long ownerId, int ownerType) {
43 String key = _encodeKey(ownerId, ownerType);
44
45 _portalCache.remove(key);
46 }
47
48 protected static Map<String, PortletPreferencesImpl> getPreferencesPool(
49 long ownerId, int ownerType) {
50 String key = _encodeKey(ownerId, ownerType);
51
52 Map<String, PortletPreferencesImpl> preferencesPool =
53 (Map<String, PortletPreferencesImpl>)_portalCache.get(key);
54
55 if (preferencesPool == null) {
56 preferencesPool =
57 new ConcurrentHashMap<String, PortletPreferencesImpl>();
58
59 _portalCache.put(key, preferencesPool);
60 }
61
62 return preferencesPool;
63 }
64
65 private static String _encodeKey(long ownerId, int ownerType) {
66 StringBundler sb = new StringBundler(5);
67
68 sb.append(CACHE_NAME);
69 sb.append(StringPool.POUND);
70 sb.append(StringUtil.toHexString(ownerId));
71 sb.append(StringPool.POUND);
72 sb.append(StringUtil.toHexString(ownerType));
73
74 return sb.toString();
75 }
76
77 private static PortalCache _portalCache = MultiVMPoolUtil.getCache(
78 CACHE_NAME);
79
80 }