1
22
23 package com.liferay.portal.webcache;
24
25 import com.liferay.portal.kernel.cache.PortalCache;
26 import com.liferay.portal.kernel.cache.SingleVMPoolUtil;
27 import com.liferay.portal.kernel.webcache.WebCacheException;
28 import com.liferay.portal.kernel.webcache.WebCacheItem;
29 import com.liferay.portal.kernel.webcache.WebCachePool;
30 import com.liferay.util.Time;
31
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34
35
41 public class WebCachePoolImpl implements WebCachePool {
42
43 public static final String CACHE_NAME = WebCachePool.class.getName();
44
45 public void clear() {
46 _cache.removeAll();
47 }
48
49 public Object get(String key, WebCacheItem wci) {
50 Object obj = SingleVMPoolUtil.get(_cache, key);
51
52 if (obj == null) {
53 try {
54 obj = wci.convert(key);
55
56 int timeToLive = (int)(wci.getRefreshTime() / Time.SECOND);
57
58 _cache.put(key, obj, timeToLive);
59 }
60 catch (WebCacheException wce) {
61 Throwable cause = wce.getCause();
62
63 if (cause != null) {
64 _log.error(cause, cause);
65 }
66 else {
67 _log.error(wce, wce);
68 }
69 }
70 }
71
72 return obj;
73 }
74
75 public void remove(String key) {
76 SingleVMPoolUtil.remove(_cache, key);
77 }
78
79 private WebCachePoolImpl() {
80 _cache = SingleVMPoolUtil.getCache(CACHE_NAME);
81 }
82
83 private static Log _log = LogFactory.getLog(WebCachePoolImpl.class);
84
85 private PortalCache _cache;
86
87 }