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