1
14
15 package com.liferay.portal.cache.memcached;
16
17 import com.liferay.portal.kernel.cache.PortalCache;
18 import com.liferay.portal.kernel.cache.PortalCacheManager;
19
20 import java.util.Map;
21 import java.util.concurrent.ConcurrentHashMap;
22 import java.util.concurrent.TimeUnit;
23
24
30 public class PooledMemcachePortalCacheManager implements PortalCacheManager {
31
32 public void afterPropertiesSet() {
33 }
34
35 public void destroy() throws Exception {
36 for (PortalCache portalCache : _portalCaches.values()) {
37 portalCache.destroy();
38 }
39 }
40
41 public void clearAll() {
42 _portalCaches.clear();
43 }
44
45 public PortalCache getCache(String name) {
46 return getCache(name, false);
47 }
48
49 public PortalCache getCache(String name, boolean blocking) {
50 PortalCache portalCache = _portalCaches.get(name);
51
52 if (portalCache == null) {
53 portalCache = new PooledMemcachePortalCache(
54 name, _memcachedClientFactory, _timeout, _timeoutTimeUnit);
55
56 portalCache.setDebug(_debug);
57
58 _portalCaches.put(name, portalCache);
59 }
60
61 return portalCache;
62 }
63
64 public void setDebug(boolean debug) {
65 _debug = debug;
66 }
67
68 public void setMemcachedClientPool(
69 MemcachedClientFactory memcachedClientFactory) {
70
71 _memcachedClientFactory = memcachedClientFactory;
72 }
73
74 public void setTimeout(int timeout) {
75 _timeout = timeout;
76 }
77
78 public void setTimeoutTimeUnit(String timeoutTimeUnit) {
79 _timeoutTimeUnit = TimeUnit.valueOf(timeoutTimeUnit);
80 }
81
82 private boolean _debug;
83 private MemcachedClientFactory _memcachedClientFactory;
84 private Map<String, PortalCache> _portalCaches =
85 new ConcurrentHashMap<String, PortalCache>();
86 private int _timeout;
87 private TimeUnit _timeoutTimeUnit;
88
89 }