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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.services.portletcache;
1819import java.io.IOException;
2021import org.apache.turbine.services.TurbineServices;
22import org.apache.turbine.services.cache.GlobalCacheService;
23import org.apache.turbine.services.cache.CachedObject;
24import org.apache.turbine.services.cache.ObjectExpiredException;
252627/***28 * This class is a static wrapper around the Turbine GlobalCacheService29 * which doesn't provide its own wrapper.30 * 31 * @see org.apache.turbine.services.cache.GlobalCacheService32 * @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 */35publicclassGlobalCache {
3637/***38 * Add an object to the cache39 *40 * @param id key of the object used by the cache to store and retrieve41 * it. Must not be null.42 * @param o the object to cache43 */44publicstaticvoid addObject( String id, CachedObject o ) {
4546 GlobalCacheService gcs = (GlobalCacheService)TurbineServices
47 .getInstance()
48 .getService( GlobalCacheService.SERVICE_NAME );
4950 gcs.addObject( id, o );
51 }
5253/***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 in59 * the cache.60 */61publicstatic CachedObject getObject(String id)
62 throws ObjectExpiredException {
6364 GlobalCacheService gcs = (GlobalCacheService)TurbineServices
65 .getInstance()
66 .getService( GlobalCacheService.SERVICE_NAME );
6768return gcs.getObject( id );
69 }
7071/***72 * Gets size, in bytes, of cache73 *74 * @return int Size, in byte, of cache75 * @exception IOException Exception passed from76 */77publicstaticint getCacheSize()
78 throws IOException {
79 GlobalCacheService gcs = (GlobalCacheService)TurbineServices
80 .getInstance()
81 .getService( GlobalCacheService.SERVICE_NAME );
8283return gcs.getCacheSize();
84 }
8586/***87 * Gets size, in bytes, of cache88 *89 * @return int, Size, in byte, of cache90 */91publicstaticint getNumberOfObjects() {
92int tempInt = 0;
93 GlobalCacheService gcs = (GlobalCacheService)TurbineServices
94 .getInstance()
95 .getService( GlobalCacheService.SERVICE_NAME );
9697 tempInt = gcs.getNumberOfObjects();
98return tempInt;
99 }
100101/***102 * Flush the cache of <B>ALL</B> objects103 */104publicvoid flushCache() {
105 GlobalCacheService gcs = (GlobalCacheService)TurbineServices
106 .getInstance()
107 .getService( GlobalCacheService.SERVICE_NAME );
108109 gcs.flushCache();
110 }
111 }