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.portlet.PortletPreferencesImpl;
22
23 import java.util.Map;
24 import java.util.concurrent.ConcurrentHashMap;
25
26
32 public class PortletPreferencesLocalUtil {
33
34 public static final String CACHE_NAME =
35 PortletPreferencesLocalUtil.class.getName();
36
37 protected static void clearPreferencesPool() {
38 _cache.removeAll();
39 }
40
41 protected static void clearPreferencesPool(long ownerId, int ownerType) {
42 String key = _encodeKey(ownerId, ownerType);
43
44 _cache.remove(key);
45 }
46
47 protected static Map<String, PortletPreferencesImpl> getPreferencesPool(
48 long ownerId, int ownerType) {
49 String key = _encodeKey(ownerId, ownerType);
50
51 Map<String, PortletPreferencesImpl> preferencesPool =
52 (Map<String, PortletPreferencesImpl>)_cache.get(key);
53
54 if (preferencesPool == null) {
55 preferencesPool =
56 new ConcurrentHashMap<String, PortletPreferencesImpl>();
57
58 _cache.put(key, preferencesPool);
59 }
60
61 return preferencesPool;
62 }
63
64 private static String _encodeKey(long ownerId, int ownerType) {
65 StringBundler sb = new StringBundler(5);
66
67 sb.append(CACHE_NAME);
68 sb.append(StringPool.POUND);
69 sb.append(ownerId);
70 sb.append(StringPool.POUND);
71 sb.append(ownerType);
72
73 return sb.toString();
74 }
75
76 private static PortalCache _cache = MultiVMPoolUtil.getCache(CACHE_NAME);
77
78 }