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.net.URL;
021
022 import java.util.Map;
023 import java.util.concurrent.ConcurrentHashMap;
024
025
028 public class MemoryPortalCacheManager implements PortalCacheManager {
029
030 public void afterPropertiesSet() {
031 _portalCaches = new ConcurrentHashMap<String, PortalCache>(
032 _cacheManagerInitialCapacity);
033 }
034
035 public void clearAll() {
036 _portalCaches.clear();
037 }
038
039 public PortalCache getCache(String name) {
040 return getCache(name, false);
041 }
042
043 public PortalCache getCache(String name, boolean blocking) {
044 PortalCache portalCache = _portalCaches.get(name);
045
046 if (portalCache == null) {
047 portalCache = new MemoryPortalCache(name, _cacheInitialCapacity);
048
049 _portalCaches.put(name, portalCache);
050 }
051
052 return portalCache;
053 }
054
055 public void reconfigureCaches(URL configurationURL) {
056 }
057
058 public void removeCache(String name) {
059 _portalCaches.remove(name);
060 }
061
062 public void setCacheInitialCapacity(int cacheInitialCapacity) {
063 _cacheInitialCapacity = cacheInitialCapacity;
064 }
065
066 public void setCacheManagerInitialCapacity(
067 int cacheManagerInitialCapacity) {
068
069 _cacheManagerInitialCapacity = cacheManagerInitialCapacity;
070 }
071
072 private int _cacheInitialCapacity = 10000;
073 private int _cacheManagerInitialCapacity = 10000;
074 private Map<String, PortalCache> _portalCaches;
075
076 }