001
014
015 package com.liferay.portal.service.impl;
016
017 import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
018 import com.liferay.portal.kernel.cache.PortalCache;
019 import com.liferay.portal.kernel.util.StringBundler;
020 import com.liferay.portal.kernel.util.StringPool;
021 import com.liferay.portlet.PortletPreferencesImpl;
022
023 import java.util.Map;
024 import java.util.concurrent.ConcurrentHashMap;
025
026
030 public class PortletPreferencesLocalUtil {
031
032 public static final String CACHE_NAME =
033 PortletPreferencesLocalUtil.class.getName();
034
035 protected static void clearPreferencesPool() {
036 _portalCache.removeAll();
037 }
038
039 protected static void clearPreferencesPool(long ownerId, int ownerType) {
040 String key = _encodeKey(ownerId, ownerType);
041
042 _portalCache.remove(key);
043 }
044
045 protected static Map<String, PortletPreferencesImpl> getPreferencesPool(
046 long ownerId, int ownerType) {
047 String key = _encodeKey(ownerId, ownerType);
048
049 Map<String, PortletPreferencesImpl> preferencesPool =
050 (Map<String, PortletPreferencesImpl>)_portalCache.get(key);
051
052 if (preferencesPool == null) {
053 preferencesPool =
054 new ConcurrentHashMap<String, PortletPreferencesImpl>();
055
056 _portalCache.put(key, preferencesPool);
057 }
058
059 return preferencesPool;
060 }
061
062 private static String _encodeKey(long ownerId, int ownerType) {
063 StringBundler sb = new StringBundler(5);
064
065 sb.append(CACHE_NAME);
066 sb.append(StringPool.POUND);
067 sb.append(ownerId);
068 sb.append(StringPool.POUND);
069 sb.append(ownerType);
070
071 return sb.toString();
072 }
073
074 private static PortalCache _portalCache = MultiVMPoolUtil.getCache(
075 CACHE_NAME);
076
077 }