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