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.util.StringUtil;
020    
021    /**
022     * @author Shuyang Zhou
023     */
024    public class PortalPreferencesWrapperCacheUtil {
025    
026            public static final String CACHE_NAME =
027                    PortalPreferencesWrapperCacheUtil.class.getName();
028    
029            public static PortalPreferencesWrapper get(long ownerId, int ownerType) {
030                    String cacheKey = _getCacheKey(ownerId, ownerType);
031    
032                    return _portalPreferencesWrapperPortalCache.get(cacheKey);
033            }
034    
035            public static void put(
036                    long ownerId, int ownerType,
037                    PortalPreferencesWrapper portalPreferencesWrapper) {
038    
039                    String cacheKey = _getCacheKey(ownerId, ownerType);
040    
041                    _portalPreferencesWrapperPortalCache.putQuiet(
042                            cacheKey, portalPreferencesWrapper);
043            }
044    
045            public static void remove(long ownerId, int ownerType) {
046                    String cacheKey = _getCacheKey(ownerId, ownerType);
047    
048                    _portalPreferencesWrapperPortalCache.remove(cacheKey);
049            }
050    
051            private static String _getCacheKey(long ownerId, int ownerType) {
052                    String cacheKey = StringUtil.toHexString(ownerId);
053    
054                    cacheKey = cacheKey.concat(StringUtil.toHexString(ownerType));
055    
056                    return cacheKey;
057            }
058    
059            private static final PortalCache<String, PortalPreferencesWrapper>
060                    _portalPreferencesWrapperPortalCache = MultiVMPoolUtil.getCache(
061                            CACHE_NAME);
062    
063    }