001
014
015 package com.liferay.portal.cache.memcached;
016
017 import com.liferay.portal.kernel.cache.PortalCache;
018 import com.liferay.portal.kernel.cache.PortalCacheManager;
019
020 import java.util.Map;
021 import java.util.concurrent.ConcurrentHashMap;
022 import java.util.concurrent.TimeUnit;
023
024
027 public class PooledMemcachePortalCacheManager implements PortalCacheManager {
028
029 public void afterPropertiesSet() {
030 }
031
032 public void destroy() throws Exception {
033 for (PortalCache portalCache : _portalCaches.values()) {
034 portalCache.destroy();
035 }
036 }
037
038 public void clearAll() {
039 _portalCaches.clear();
040 }
041
042 public PortalCache getCache(String name) {
043 return getCache(name, false);
044 }
045
046 public PortalCache getCache(String name, boolean blocking) {
047 PortalCache portalCache = _portalCaches.get(name);
048
049 if (portalCache == null) {
050 portalCache = new PooledMemcachePortalCache(
051 name, _memcachedClientFactory, _timeout, _timeoutTimeUnit);
052
053 portalCache.setDebug(_debug);
054
055 _portalCaches.put(name, portalCache);
056 }
057
058 return portalCache;
059 }
060
061 public void setDebug(boolean debug) {
062 _debug = debug;
063 }
064
065 public void setMemcachedClientPool(
066 MemcachedClientFactory memcachedClientFactory) {
067
068 _memcachedClientFactory = memcachedClientFactory;
069 }
070
071 public void setTimeout(int timeout) {
072 _timeout = timeout;
073 }
074
075 public void setTimeoutTimeUnit(String timeoutTimeUnit) {
076 _timeoutTimeUnit = TimeUnit.valueOf(timeoutTimeUnit);
077 }
078
079 private boolean _debug;
080 private MemcachedClientFactory _memcachedClientFactory;
081 private Map<String, PortalCache> _portalCaches =
082 new ConcurrentHashMap<String, PortalCache>();
083 private int _timeout;
084 private TimeUnit _timeoutTimeUnit;
085
086 }