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