1
22
23 package com.liferay.portal.kernel.cache;
24
25 import com.liferay.portal.kernel.log.Log;
26 import com.liferay.portal.kernel.log.LogFactoryUtil;
27
28 import java.util.Map;
29 import java.util.concurrent.ConcurrentHashMap;
30
31
36 public class CacheRegistry {
37
38 public static void clear() {
39 for (Map.Entry<String, CacheRegistryItem> entry : _items.entrySet()) {
40 CacheRegistryItem item = entry.getValue();
41
42 if (_log.isDebugEnabled()) {
43 _log.debug("Invalidating " + item.getRegistryName());
44 }
45
46 item.invalidate();
47 }
48 }
49
50 public static void clear(String name) {
51 CacheRegistryItem item = _items.get(name);
52
53 if (item != null) {
54 if (_log.isDebugEnabled()) {
55 _log.debug("Invalidating " + name);
56 }
57
58 item.invalidate();
59 }
60 else {
61 _log.error("No cache registry found with name " + name);
62 }
63 }
64
65 public static boolean isActive() {
66 return _active;
67 }
68
69 public static void register(CacheRegistryItem item) {
70 String name = item.getRegistryName();
71
72 if (_log.isDebugEnabled()) {
73 _log.debug("Registering " + name);
74 }
75
76 if (_items.containsKey(name)) {
77 if (_log.isDebugEnabled()) {
78 _log.debug("Not registering duplicate " + name);
79 }
80 }
81 else {
82 _items.put(name, item);
83 }
84 }
85
86 public static void setActive(boolean active) {
87 _active = active;
88
89 if (!active) {
90 clear();
91 }
92 }
93
94 public static void unregister(String name) {
95 if (_log.isDebugEnabled()) {
96 _log.debug("Unregistering " + name);
97 }
98
99 _items.remove(name);
100 }
101
102 private static Log _log = LogFactoryUtil.getLog(CacheRegistry.class);
103
104 private static boolean _active = true;
105 private static Map<String, CacheRegistryItem> _items =
106 new ConcurrentHashMap<String, CacheRegistryItem>();
107
108 }