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.net.URL;
021
022 import java.util.Map;
023 import java.util.concurrent.ConcurrentHashMap;
024 import java.util.concurrent.TimeUnit;
025
026
029 public class PooledMemcachePortalCacheManager implements PortalCacheManager {
030
031 public void afterPropertiesSet() {
032 }
033
034 @Override
035 public void clearAll() {
036 _portalCaches.clear();
037 }
038
039 public void destroy() throws Exception {
040 for (PortalCache portalCache : _portalCaches.values()) {
041 portalCache.destroy();
042 }
043 }
044
045 @Override
046 public PortalCache getCache(String name) {
047 return getCache(name, false);
048 }
049
050 @Override
051 public PortalCache getCache(String name, boolean blocking) {
052 PortalCache portalCache = _portalCaches.get(name);
053
054 if (portalCache == null) {
055 portalCache = new PooledMemcachePortalCache(
056 name, _memcachedClientFactory, _timeout, _timeoutTimeUnit);
057
058 _portalCaches.put(name, portalCache);
059 }
060
061 return portalCache;
062 }
063
064 @Override
065 public void reconfigureCaches(URL configurationURL) {
066 }
067
068 @Override
069 public void removeCache(String name) {
070 _portalCaches.remove(name);
071 }
072
073 public void setMemcachedClientPool(
074 MemcachedClientFactory memcachedClientFactory) {
075
076 _memcachedClientFactory = memcachedClientFactory;
077 }
078
079 public void setTimeout(int timeout) {
080 _timeout = timeout;
081 }
082
083 public void setTimeoutTimeUnit(String timeoutTimeUnit) {
084 _timeoutTimeUnit = TimeUnit.valueOf(timeoutTimeUnit);
085 }
086
087 private MemcachedClientFactory _memcachedClientFactory;
088 private Map<String, PortalCache> _portalCaches =
089 new ConcurrentHashMap<String, PortalCache>();
090 private int _timeout;
091 private TimeUnit _timeoutTimeUnit;
092
093 }