KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > portletcache > GlobalCache


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

16
17 package org.apache.jetspeed.services.portletcache;
18
19 import java.io.IOException JavaDoc;
20
21 import org.apache.turbine.services.TurbineServices;
22 import org.apache.turbine.services.cache.GlobalCacheService;
23 import org.apache.turbine.services.cache.CachedObject;
24 import org.apache.turbine.services.cache.ObjectExpiredException;
25
26
27 /**
28  * This class is a static wrapper around the Turbine GlobalCacheService
29  * which doesn't provide its own wrapper.
30  *
31  * @see org.apache.turbine.services.cache.GlobalCacheService
32  * @author <a HREF="mailto:raphael@apache.org">RaphaŽl Luta</a>
33  * @version $Id: GlobalCache.java,v 1.7 2004/02/23 03:34:54 jford Exp $
34  */

35 public class GlobalCache {
36         
37     /**
38      * Add an object to the cache
39      *
40      * @param id key of the object used by the cache to store and retrieve
41      * it. Must not be null.
42      * @param o the object to cache
43      */

44     public static void addObject( String JavaDoc id, CachedObject o ) {
45
46         GlobalCacheService gcs = (GlobalCacheService)TurbineServices
47             .getInstance()
48             .getService( GlobalCacheService.SERVICE_NAME );
49             
50         gcs.addObject( id, o );
51     }
52     
53     /**
54      * Gets a cached object given its id (a String).
55      *
56      * @param id The String id for the object.
57      * @return A CachedObject.
58      * @exception ObjectExpiredException The object has expired in
59      * the cache.
60      */

61     public static CachedObject getObject(String JavaDoc id)
62         throws ObjectExpiredException {
63
64         GlobalCacheService gcs = (GlobalCacheService)TurbineServices
65             .getInstance()
66             .getService( GlobalCacheService.SERVICE_NAME );
67             
68         return gcs.getObject( id );
69     }
70     
71     /**
72      * Gets size, in bytes, of cache
73      *
74      * @return int Size, in byte, of cache
75      * @exception IOException Exception passed from
76      */

77     public static int getCacheSize()
78     throws IOException JavaDoc {
79         GlobalCacheService gcs = (GlobalCacheService)TurbineServices
80             .getInstance()
81             .getService( GlobalCacheService.SERVICE_NAME );
82         
83         return gcs.getCacheSize();
84     }
85     
86     /**
87      * Gets size, in bytes, of cache
88      *
89      * @return int, Size, in byte, of cache
90      */

91     public static int getNumberOfObjects() {
92         int tempInt = 0;
93         GlobalCacheService gcs = (GlobalCacheService)TurbineServices
94             .getInstance()
95             .getService( GlobalCacheService.SERVICE_NAME );
96         
97         tempInt = gcs.getNumberOfObjects();
98         return tempInt;
99     }
100     
101     /**
102      * Flush the cache of <B>ALL</B> objects
103      */

104     public void flushCache() {
105         GlobalCacheService gcs = (GlobalCacheService)TurbineServices
106             .getInstance()
107             .getService( GlobalCacheService.SERVICE_NAME );
108         
109         gcs.flushCache();
110     }
111 }
112
Popular Tags