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