Clover Coverage Report - Atlassian Core
Coverage timestamp: Sun Nov 30 2008 18:33:35 CST
24   87   8   12
8   59   0.33   2
2     4  
1    
 
 
  CacheUtils       Line # 22 24 8 0% 0.0
 
No Tests
 
1    /*
2    * Created by IntelliJ IDEA.
3    * User: Administrator
4    * Date: 10/07/2002
5    * Time: 14:31:20
6    * To change template for new class use
7    * Code Style | Class Templates options (Tools | IDE Options).
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    * Utility class to handle cache flushing.
21    */
 
22    public class CacheUtils
23    {
24    private static final Category log = Category.getInstance(CacheUtils.class);
25   
26    /**
27    * Flush the web tier caches given a key.
28    * <p>
29    * The different keys used are:
30    * assignee, status, summary, type, version, priority
31    */
 
32  0 toggle public static void flushCache(String key)
33    {
34  0 try
35    {
36  0 Map applicationCaches = ServletCacheAdministrator.getApplicationCaches();
37  0 for (Iterator iterator = applicationCaches.entrySet().iterator(); iterator.hasNext();)
38    {
39  0 Map.Entry entry = (Map.Entry) iterator.next();
40  0 Cache cache = (Cache) entry.getValue();
41  0 cache.flushPattern(key);
42    }
43   
44  0 Map sessionCaches = ServletCacheAdministrator.getSessionCaches();
45  0 for (Iterator iterator = sessionCaches.entrySet().iterator(); iterator.hasNext();)
46    {
47  0 Map.Entry entry = (Map.Entry) iterator.next();
48  0 Cache cache = (Cache) entry.getValue();
49  0 cache.flushPattern(key);
50    }
51    }
52    catch (Exception e)
53    {
54  0 log.error("Error flushing caches matching key : " + key + " : " + e, e);
55    }
56    }
57   
58    /**
59    * Flush all the web tier caches
60    */
 
61  0 toggle public static void flushAll()
62    {
63   
64  0 try
65    {
66  0 Map applicationCaches = ServletCacheAdministrator.getApplicationCaches();
67  0 for (Iterator iterator = applicationCaches.entrySet().iterator(); iterator.hasNext();)
68    {
69  0 Map.Entry entry = (Map.Entry) iterator.next();
70  0 Cache cache = (Cache) entry.getValue();
71  0 cache.flushAll(new Date());
72    }
73   
74  0 Map sessionCaches = ServletCacheAdministrator.getSessionCaches();
75  0 for (Iterator iterator = sessionCaches.entrySet().iterator(); iterator.hasNext();)
76    {
77  0 Map.Entry entry = (Map.Entry) iterator.next();
78  0 Cache cache = (Cache) entry.getValue();
79  0 cache.flushAll(new Date());
80    }
81    }
82    catch (Exception e)
83    {
84  0 log.error("Error flushing all caches: " + e, e);
85    }
86    }
87    }