01: package org.apache.turbine.services.cache;
02:
03: /*
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
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: * Utility method for accessing the service
39: * implementation
40: *
41: * @return a GlobalCacheService implementation instance
42: */
43: protected static GlobalCacheService getService() {
44: return (GlobalCacheService) TurbineServices.getInstance()
45: .getService(GlobalCacheService.SERVICE_NAME);
46: }
47:
48: /**
49: * Gets a cached object given its id (a String).
50: *
51: * @param id The String id for the object.
52: * @return A CachedObject.
53: * @exception ObjectExpiredException, if the object has expired in
54: * the cache.
55: */
56: public static CachedObject getObject(String id)
57: throws ObjectExpiredException {
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 id, CachedObject o) {
68: getService().addObject(id, o);
69: }
70:
71: /**
72: * Removes an object from the cache.
73: *
74: * @param id The String id for the object.
75: */
76: public static void removeObject(String id) {
77: getService().removeObject(id);
78: }
79:
80: /**
81: * Returns the current size of the cache.
82: * @return int representing current cache size in number of bytes
83: */
84: public static int getCacheSize() throws IOException {
85: return getService().getCacheSize();
86: }
87:
88: /**
89: * Returns the number of objects in the cache.
90: * @return int The current number of objects in the cache.
91: */
92: public static int getNumberOfObjects() {
93: return getService().getNumberOfObjects();
94: }
95: }
|