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.Validator;
22 import com.liferay.util.servlet.filters.CacheResponseData;
23
24
30 public class CacheUtil {
31
32 public static String CACHE_NAME = CacheUtil.class.getName();
33
34 public static void clearCache() {
35 _cache.removeAll();
36 }
37
38 public static void clearCache(long companyId) {
39 clearCache();
40 }
41
42 public static CacheResponseData getCacheResponseData(
43 long companyId, String key) {
44
45 if (Validator.isNull(key)) {
46 return null;
47 }
48
49 key = _encodeKey(companyId, key);
50
51 CacheResponseData data = (CacheResponseData)_cache.get(key);
52
53 return data;
54 }
55
56 public static void putCacheResponseData(
57 long companyId, String key, CacheResponseData data) {
58
59 if (data != null) {
60 key = _encodeKey(companyId, key);
61
62 _cache.put(key, data);
63 }
64 }
65
66 private static String _encodeKey(long companyId, String key) {
67 StringBundler sb = new StringBundler(5);
68
69 sb.append(CACHE_NAME);
70 sb.append(StringPool.POUND);
71 sb.append(companyId);
72 sb.append(StringPool.POUND);
73 sb.append(key);
74
75 return sb.toString();
76 }
77
78 private static PortalCache _cache = MultiVMPoolUtil.getCache(CACHE_NAME);
79
80 }