1 package org.apache.turbine.services.cache;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.IOException;
23
24 import org.apache.turbine.services.TurbineServices;
25
26 /***
27 * This is a Facade class for GlobalCacheService.
28 *
29 * This class provides static methods that call related methods of the
30 * implementation of the GlobalCacheService used by the System, according to
31 * the settings in TurbineResources.
32 *
33 * @author <a href="mailto:sean@informage.net">Sean Legassick</a>
34 * @version $Id: TurbineGlobalCache.java 534527 2007-05-02 16:10:59Z tv $
35 */
36 public abstract class TurbineGlobalCache
37 {
38 /***
39 * Utility method for accessing the service
40 * implementation
41 *
42 * @return a GlobalCacheService implementation instance
43 */
44 protected static GlobalCacheService getService()
45 {
46 return (GlobalCacheService) TurbineServices
47 .getInstance().getService(GlobalCacheService.SERVICE_NAME);
48 }
49
50 /***
51 * Gets a cached object given its id (a String).
52 *
53 * @param id The String id for the object.
54 * @return A CachedObject.
55 * @exception ObjectExpiredException, if the object has expired in
56 * the cache.
57 */
58 public static CachedObject getObject(String id)
59 throws ObjectExpiredException
60 {
61 return getService().getObject(id);
62 }
63
64 /***
65 * Adds an object to the cache.
66 *
67 * @param id The String id for the object.
68 * @param o The object to add to the cache.
69 */
70 public static void addObject(String id,
71 CachedObject o)
72 {
73 getService().addObject(id, o);
74 }
75
76 /***
77 * Removes an object from the cache.
78 *
79 * @param id The String id for the object.
80 */
81 public static void removeObject(String id)
82 {
83 getService().removeObject(id);
84 }
85
86 /***
87 * Returns the current size of the cache.
88 * @return int representing current cache size in number of bytes
89 */
90 public static int getCacheSize()
91 throws IOException
92 {
93 return getService().getCacheSize();
94 }
95
96 /***
97 * Returns the number of objects in the cache.
98 * @return int The current number of objects in the cache.
99 */
100 public static int getNumberOfObjects()
101 {
102 return getService().getNumberOfObjects();
103 }
104 }