001
014
015 package com.liferay.portal.servlet.filters.cache;
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.portal.kernel.util.Validator;
022 import com.liferay.util.servlet.filters.CacheResponseData;
023
024
028 public class CacheUtil {
029
030 public static String CACHE_NAME = CacheUtil.class.getName();
031
032 public static void clearCache() {
033 _portalCache.removeAll();
034 }
035
036 public static void clearCache(long companyId) {
037 clearCache();
038 }
039
040 public static CacheResponseData getCacheResponseData(
041 long companyId, String key) {
042
043 if (Validator.isNull(key)) {
044 return null;
045 }
046
047 key = _encodeKey(companyId, key);
048
049 CacheResponseData data = (CacheResponseData)_portalCache.get(key);
050
051 return data;
052 }
053
054 public static void putCacheResponseData(
055 long companyId, String key, CacheResponseData data) {
056
057 if (data != null) {
058 key = _encodeKey(companyId, key);
059
060 _portalCache.put(key, data);
061 }
062 }
063
064 private static String _encodeKey(long companyId, String key) {
065 StringBundler sb = new StringBundler(5);
066
067 sb.append(CACHE_NAME);
068 sb.append(StringPool.POUND);
069 sb.append(companyId);
070 sb.append(StringPool.POUND);
071 sb.append(key);
072
073 return sb.toString();
074 }
075
076 private static PortalCache _portalCache = MultiVMPoolUtil.getCache(
077 CACHE_NAME);
078
079 }