1
14
15 package com.liferay.portal.webcache;
16
17 import com.liferay.portal.kernel.cache.PortalCache;
18 import com.liferay.portal.kernel.cache.SingleVMPool;
19 import com.liferay.portal.kernel.log.Log;
20 import com.liferay.portal.kernel.log.LogFactoryUtil;
21 import com.liferay.portal.kernel.util.Time;
22 import com.liferay.portal.kernel.webcache.WebCacheException;
23 import com.liferay.portal.kernel.webcache.WebCacheItem;
24 import com.liferay.portal.kernel.webcache.WebCachePool;
25
26
31 public class WebCachePoolImpl implements WebCachePool {
32
33 public static final String CACHE_NAME = WebCachePool.class.getName();
34
35 public void afterPropertiesSet() {
36 _cache = _singleVMPool.getCache(CACHE_NAME);
37 }
38
39 public void clear() {
40 _cache.removeAll();
41 }
42
43 public Object get(String key, WebCacheItem wci) {
44 Object obj = _cache.get(key);
45
46 if (obj == null) {
47 try {
48 obj = wci.convert(key);
49
50 int timeToLive = (int)(wci.getRefreshTime() / Time.SECOND);
51
52 _cache.put(key, obj, timeToLive);
53 }
54 catch (WebCacheException wce) {
55 if (_log.isWarnEnabled()) {
56 Throwable cause = wce.getCause();
57
58 if (cause != null) {
59 _log.warn(cause, cause);
60 }
61 else {
62 _log.warn(wce, wce);
63 }
64 }
65 }
66 }
67
68 return obj;
69 }
70
71 public void remove(String key) {
72 _cache.remove(key);
73 }
74
75 public void setSingleVMPool(SingleVMPool singleVMPool) {
76 _singleVMPool = singleVMPool;
77 }
78
79 private static Log _log = LogFactoryUtil.getLog(WebCachePoolImpl.class);
80
81 private SingleVMPool _singleVMPool;
82 private PortalCache _cache;
83
84 }