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