1
14
15 package com.liferay.portal.servlet.filters.cache;
16
17 import com.liferay.portal.kernel.cache.MultiVMPoolUtil;
18 import com.liferay.portal.kernel.cache.PortalCache;
19 import com.liferay.portal.kernel.util.StringBundler;
20 import com.liferay.portal.kernel.util.StringPool;
21 import com.liferay.portal.kernel.util.StringUtil;
22 import com.liferay.portal.kernel.util.Validator;
23 import com.liferay.util.servlet.filters.CacheResponseData;
24
25
31 public class CacheUtil {
32
33 public static String CACHE_NAME = CacheUtil.class.getName();
34
35 public static void clearCache() {
36 _portalCache.removeAll();
37 }
38
39 public static void clearCache(long companyId) {
40 clearCache();
41 }
42
43 public static CacheResponseData getCacheResponseData(
44 long companyId, String key) {
45
46 if (Validator.isNull(key)) {
47 return null;
48 }
49
50 key = _encodeKey(companyId, key);
51
52 CacheResponseData data = (CacheResponseData)_portalCache.get(key);
53
54 return data;
55 }
56
57 public static void putCacheResponseData(
58 long companyId, String key, CacheResponseData data) {
59
60 if (data != null) {
61 key = _encodeKey(companyId, key);
62
63 _portalCache.put(key, data);
64 }
65 }
66
67 private static String _encodeKey(long companyId, String key) {
68 StringBundler sb = new StringBundler(5);
69
70 sb.append(CACHE_NAME);
71 sb.append(StringPool.POUND);
72 sb.append(StringUtil.toHexString(companyId));
73 sb.append(StringPool.POUND);
74 sb.append(key);
75
76 return sb.toString();
77 }
78
79 private static PortalCache _portalCache = MultiVMPoolUtil.getCache(
80 CACHE_NAME);
81
82 }