001package org.apache.fulcrum.cache;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import java.io.IOException;
023import java.util.List;
024
025/**
026 * GlobalCacheService interface.
027 *
028 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a>
029 * @author <a href="mailto:peter@courefreshableCachedObjectux.biz">Peter CourefreshableCachedObjectux</a>
030 * @version $Id$
031 */
032public interface GlobalCacheService
033{
034    /** Avalon role - used to id the component within the manager */
035    String ROLE = GlobalCacheService.class.getName();
036
037    /**
038     * Gets a cached object given its id (a String).
039     *
040     * @param <T> type of object to return
041     * @param objectId
042     *            The String id for the object.
043     * @return A CachedObject.
044     * @throws ObjectExpiredException
045     *                if the object has expired in the cache.
046     */
047    <T> CachedObject<T> getObject(String objectId) throws ObjectExpiredException;
048
049    /**
050     * Adds an object to the cache.
051     *
052     * @param <T> type of object to add
053     * @param objectId
054     *            The String id for the object.
055     * @param object
056     *            The object to add to the cache.
057     */
058    <T> void addObject(String objectId, CachedObject<T> object);
059
060    /**
061     * Removes an object from the cache.
062     *
063     * @param objectId
064     *            The String id for the object.
065     */
066    void removeObject(String objectId);
067
068    /**
069     * Returns a copy of keys to objects in the cache as a list.
070     *
071     * Note that keys to expired objects are not returned.
072     *
073     * @return A List of <code>String</code>'s representing the keys to
074     *         objects in the cache.
075     */
076    List<String> getKeys();
077
078    /**
079     * Returns a copy of the non-expired CachedObjects in the cache as a list.
080     *
081     * @return A List of <code>CachedObject</code> objects held in the cache
082     */
083    List<CachedObject<?>> getCachedObjects();
084
085    /**
086     * Returns the current size of the cache.
087     *
088     * @return int representing current cache size in number of bytes
089     * @throws IOException if unable to return cache size
090     */
091    int getCacheSize() throws IOException;
092
093    /**
094     * Returns the number of objects in the cache.
095     *
096     * @return int The current number of objects in the cache.
097     */
098    int getNumberOfObjects();
099
100    /**
101     * Flush the cache of all objects.
102     */
103    void flushCache();
104}