API Overview API Index Package Overview Direct link to this page
JavaOnTracks 0.1.2
  net.jot.utils.caching. CacheManager View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

font color='#880088'>
package net.jot.utils.caching;

import java.util.Iterator;

/**
 * Central class to Manage of all the caches
 * It is a Cache of Cache items.
 * All the cache keys should be declared here, so it's simpler to keep track
 *
 * Example of use:
 * 		Cache cache = CacheManager.getInstance().getSubCache(CacheManager.SOME_CACHE_KEY, new CacheObjectProvider());
 * 		CacheProvider provider=new CacheProviderImpl(someRequiredArg);
 *		return cache.get("something", provider);
 *
 * @author thibautc
 */
public class CacheManager extends Cache
{

	private static final CacheManager instance = new CacheManager();
	//Cache keys
	// Ex: public static final String SOME_CACHE_KEY = "SOME_CACHE_KEY";

	public static CacheManager getInstance()
	{
		return instance;
	}

	private CacheManager()
	{
		setName("CacheManager");
	}

	public Cache getSubCache(String name, CacheProvider provider)
	{
		return (Cache)get(name, provider);
	}

	/**
	 * Overload to return the stats of all the included caches
	 * @return
	 */
	public String getStats()
	{
		StringBuffer sb = new StringBuffer(super.getStats());
		Iterator it = keys().iterator();
		while (it.hasNext())
		{
			String key = (String) it.next();
			Cache c = (Cache) get(key, null);
			// check for null, could have been deleted since or be null in value
			if (c != null)
			{
				sb.append("\n\t");
				sb.append(key);
				sb.append(" -> ");
				sb.append(c.getStats());
			}
		}
		return sb.toString();
	}

	public String getHtmlStats()
	{
		return getStats().replaceAll("\t", "&nbsp;&nbsp;").replaceAll("\n", "<br/>");
	}

}

Generated By: JavaOnTracks Doclet 0.1.5     ©Thibaut Colar