KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > turbine > services > cache > TurbineGlobalCache


1 package org.apache.turbine.services.cache;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License")
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import java.io.IOException JavaDoc;
20
21 import org.apache.turbine.services.TurbineServices;
22
23 /**
24  * This is a Facade class for GlobalCacheService.
25  *
26  * This class provides static methods that call related methods of the
27  * implementation of the GlobalCacheService used by the System, according to
28  * the settings in TurbineResources.
29  *
30  * @author <a HREF="mailto:sean@informage.net">Sean Legassick</a>
31  * @version $Id: TurbineGlobalCache.java,v 1.5.2.2 2004/05/20 03:05:19 seade Exp $
32  */

33 public abstract class TurbineGlobalCache
34 {
35     /**
36      * Utility method for accessing the service
37      * implementation
38      *
39      * @return a GlobalCacheService implementation instance
40      */

41     protected static GlobalCacheService getService()
42     {
43         return (GlobalCacheService) TurbineServices
44                 .getInstance().getService(GlobalCacheService.SERVICE_NAME);
45     }
46
47     /**
48      * Gets a cached object given its id (a String).
49      *
50      * @param id The String id for the object.
51      * @return A CachedObject.
52      * @exception ObjectExpiredException, if the object has expired in
53      * the cache.
54      */

55     public static CachedObject getObject(String JavaDoc id)
56             throws ObjectExpiredException
57     {
58         return getService().getObject(id);
59     }
60
61     /**
62      * Adds an object to the cache.
63      *
64      * @param id The String id for the object.
65      * @param o The object to add to the cache.
66      */

67     public static void addObject(String JavaDoc id,
68                                  CachedObject o)
69     {
70         getService().addObject(id, o);
71     }
72
73     /**
74      * Removes an object from the cache.
75      *
76      * @param id The String id for the object.
77      */

78     public static void removeObject(String JavaDoc id)
79     {
80         getService().removeObject(id);
81     }
82
83     /**
84      * Returns the current size of the cache.
85      * @return int representing current cache size in number of bytes
86      */

87     public static int getCacheSize()
88             throws IOException JavaDoc
89     {
90         return getService().getCacheSize();
91     }
92
93     /**
94      * Returns the number of objects in the cache.
95      * @return int The current number of objects in the cache.
96      */

97     public static int getNumberOfObjects()
98     {
99         return getService().getNumberOfObjects();
100     }
101 }
102
Popular Tags