1
14
15 package com.liferay.portal.cache.memory;
16
17 import com.liferay.portal.kernel.cache.PortalCache;
18 import com.liferay.portal.kernel.cache.PortalCacheManager;
19
20 import java.util.Map;
21 import java.util.concurrent.ConcurrentHashMap;
22
23
28 public class MemoryPortalCacheManager implements PortalCacheManager {
29
30 public void afterPropertiesSet() {
31 _portalCaches = new ConcurrentHashMap<String, PortalCache>(
32 _cacheManagerInitialCapacity);
33 }
34
35 public void clearAll() {
36 _portalCaches.clear();
37 }
38
39 public PortalCache getCache(String name) {
40 return getCache(name, false);
41 }
42
43 public PortalCache getCache(String name, boolean blocking) {
44 PortalCache portalCache = _portalCaches.get(name);
45
46 if (portalCache == null) {
47 portalCache = new MemoryPortalCache(_cacheInitialCapacity);
48
49 portalCache.setDebug(_debug);
50
51 _portalCaches.put(name, portalCache);
52 }
53
54 return portalCache;
55 }
56
57 public void removeCache(String name) {
58 _portalCaches.remove(name);
59 }
60
61 public void setCacheInitialCapacity(int cacheInitialCapacity) {
62 _cacheInitialCapacity = cacheInitialCapacity;
63 }
64
65 public void setCacheManagerInitialCapacity(
66 int cacheManagerInitialCapacity) {
67
68 _cacheManagerInitialCapacity = cacheManagerInitialCapacity;
69 }
70
71 public void setDebug(boolean debug) {
72 _debug = debug;
73 }
74
75 private int _cacheInitialCapacity = 10000;
76 private int _cacheManagerInitialCapacity = 10000;
77 private boolean _debug;
78 private Map<String, PortalCache> _portalCaches;
79
80 }