001
014
015 package com.liferay.portal.cache.memory;
016
017 import com.liferay.portal.kernel.cache.PortalCache;
018 import com.liferay.portal.kernel.cache.PortalCacheManager;
019
020 import java.io.Serializable;
021
022 import java.net.URL;
023
024 import java.util.Map;
025 import java.util.concurrent.ConcurrentHashMap;
026
027
030 public class MemoryPortalCacheManager<K extends Serializable, V>
031 implements PortalCacheManager<K, V> {
032
033 public void afterPropertiesSet() {
034 _portalCaches = new ConcurrentHashMap<String, PortalCache<K, V>>(
035 _cacheManagerInitialCapacity);
036 }
037
038 public void clearAll() {
039 _portalCaches.clear();
040 }
041
042 public PortalCache<K, V> getCache(String name) {
043 return getCache(name, false);
044 }
045
046 public PortalCache<K, V> getCache(String name, boolean blocking) {
047 PortalCache<K, V> portalCache = _portalCaches.get(name);
048
049 if (portalCache == null) {
050 portalCache = new MemoryPortalCache<K, V>(
051 name, _cacheInitialCapacity);
052
053 _portalCaches.put(name, portalCache);
054 }
055
056 return portalCache;
057 }
058
059 public void reconfigureCaches(URL configurationURL) {
060 }
061
062 public void removeCache(String name) {
063 _portalCaches.remove(name);
064 }
065
066 public void setCacheInitialCapacity(int cacheInitialCapacity) {
067 _cacheInitialCapacity = cacheInitialCapacity;
068 }
069
070 public void setCacheManagerInitialCapacity(
071 int cacheManagerInitialCapacity) {
072
073 _cacheManagerInitialCapacity = cacheManagerInitialCapacity;
074 }
075
076 private int _cacheInitialCapacity = 10000;
077 private int _cacheManagerInitialCapacity = 10000;
078 private Map<String, PortalCache<K, V>> _portalCaches;
079
080 }