1
2
3
4
5
6
7
8
9 package com.atlassian.core.util;
10
11 import com.opensymphony.module.oscache.base.Cache;
12 import com.opensymphony.module.oscache.web.ServletCacheAdministrator;
13 import org.apache.log4j.Category;
14
15 import java.util.Date;
16 import java.util.Iterator;
17 import java.util.Map;
18
19
20
21
22 public class CacheUtils
23 {
24 private static final Category log = Category.getInstance(CacheUtils.class);
25
26
27
28
29
30
31
32 public static void flushCache(String key)
33 {
34 try
35 {
36 Map applicationCaches = ServletCacheAdministrator.getApplicationCaches();
37 for (Iterator iterator = applicationCaches.entrySet().iterator(); iterator.hasNext();)
38 {
39 Map.Entry entry = (Map.Entry) iterator.next();
40 Cache cache = (Cache) entry.getValue();
41 cache.flushPattern(key);
42 }
43
44 Map sessionCaches = ServletCacheAdministrator.getSessionCaches();
45 for (Iterator iterator = sessionCaches.entrySet().iterator(); iterator.hasNext();)
46 {
47 Map.Entry entry = (Map.Entry) iterator.next();
48 Cache cache = (Cache) entry.getValue();
49 cache.flushPattern(key);
50 }
51 }
52 catch (Exception e)
53 {
54 log.error("Error flushing caches matching key : " + key + " : " + e, e);
55 }
56 }
57
58
59
60
61 public static void flushAll()
62 {
63
64 try
65 {
66 Map applicationCaches = ServletCacheAdministrator.getApplicationCaches();
67 for (Iterator iterator = applicationCaches.entrySet().iterator(); iterator.hasNext();)
68 {
69 Map.Entry entry = (Map.Entry) iterator.next();
70 Cache cache = (Cache) entry.getValue();
71 cache.flushAll(new Date());
72 }
73
74 Map sessionCaches = ServletCacheAdministrator.getSessionCaches();
75 for (Iterator iterator = sessionCaches.entrySet().iterator(); iterator.hasNext();)
76 {
77 Map.Entry entry = (Map.Entry) iterator.next();
78 Cache cache = (Cache) entry.getValue();
79 cache.flushAll(new Date());
80 }
81 }
82 catch (Exception e)
83 {
84 log.error("Error flushing all caches: " + e, e);
85 }
86 }
87 }