001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet;
016    
017    import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
018    import com.liferay.portal.kernel.cache.PortalCache;
019    import com.liferay.portal.kernel.cache.PortalCacheHelperUtil;
020    import com.liferay.portal.kernel.util.StringUtil;
021    
022    /**
023     * @author Shuyang Zhou
024     */
025    public class PortalPreferencesWrapperCacheUtil {
026    
027            public static final String CACHE_NAME =
028                    PortalPreferencesWrapperCacheUtil.class.getName();
029    
030            public static PortalPreferencesWrapper get(long ownerId, int ownerType) {
031                    String cacheKey = _getCacheKey(ownerId, ownerType);
032    
033                    return _portalPreferencesWrapperPortalCache.get(cacheKey);
034            }
035    
036            public static void put(
037                    long ownerId, int ownerType,
038                    PortalPreferencesWrapper portalPreferencesWrapper) {
039    
040                    String cacheKey = _getCacheKey(ownerId, ownerType);
041    
042                    PortalCacheHelperUtil.putWithoutReplicator(
043                            _portalPreferencesWrapperPortalCache, cacheKey,
044                            portalPreferencesWrapper);
045            }
046    
047            public static void remove(long ownerId, int ownerType) {
048                    String cacheKey = _getCacheKey(ownerId, ownerType);
049    
050                    _portalPreferencesWrapperPortalCache.remove(cacheKey);
051            }
052    
053            private static String _getCacheKey(long ownerId, int ownerType) {
054                    String cacheKey = StringUtil.toHexString(ownerId);
055    
056                    cacheKey = cacheKey.concat(StringUtil.toHexString(ownerType));
057    
058                    return cacheKey;
059            }
060    
061            private static final PortalCache<String, PortalPreferencesWrapper>
062                    _portalPreferencesWrapperPortalCache = MultiVMPoolUtil.getPortalCache(
063                            CACHE_NAME);
064    
065    }