001package org.apache.commons.jcs.access.behavior;
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 org.apache.commons.jcs.access.exception.CacheException;
023import org.apache.commons.jcs.engine.behavior.ICompositeCacheAttributes;
024import org.apache.commons.jcs.engine.behavior.IElementAttributes;
025import org.apache.commons.jcs.engine.stats.behavior.ICacheStats;
026
027/**
028 * ICacheAccessManagement defines the methods for cache management, cleanup and shutdown.
029 */
030public interface ICacheAccessManagement
031{
032    /**
033     * Dispose this region. Flushes objects to and closes auxiliary caches. This is a shutdown
034     * command!
035     * <p>
036     * To simply remove all elements from the region use clear().
037     */
038    void dispose();
039
040    /**
041     * Removes all of the elements from a region.
042     * <p>
043     * @throws CacheException
044     */
045    void clear() throws CacheException;
046
047    /**
048     * GetElementAttributes will return an attribute object describing the current attributes
049     * associated with the object name. If no name parameter is available, the attributes for the
050     * region will be returned. The name object must override the Object.equals and Object.hashCode
051     * methods.
052     * <p>
053     * @return The elementAttributes value
054     * @throws CacheException
055     */
056    IElementAttributes getDefaultElementAttributes()
057        throws CacheException;
058
059    /**
060     * This method is does not reset the attributes for items already in the cache. It could
061     * potentially do this for items in memory, and maybe on disk (which would be slow) but not
062     * remote items. Rather than have unpredictable behavior, this method just sets the default
063     * attributes. Items subsequently put into the cache will use these defaults if they do not
064     * specify specific attributes.
065     * <p>
066     * @param attr the default attributes.
067     * @throws CacheException if something goes wrong.
068     */
069    void setDefaultElementAttributes( IElementAttributes attr ) throws CacheException;
070
071    /**
072     * Gets the ICompositeCacheAttributes of the cache region
073     * <p>
074     * @return ICompositeCacheAttributes
075     */
076    ICompositeCacheAttributes getCacheAttributes();
077
078    /**
079     * Sets the ICompositeCacheAttributes of the cache region
080     * <p>
081     * @param cattr The new ICompositeCacheAttribute value
082     */
083    void setCacheAttributes( ICompositeCacheAttributes cattr );
084
085    /**
086     * This instructs the memory cache to remove the <i>numberToFree</i> according to its eviction
087     * policy. For example, the LRUMemoryCache will remove the <i>numberToFree</i> least recently
088     * used items. These will be spooled to disk if a disk auxiliary is available.
089     * <p>
090     * @param numberToFree
091     * @return the number that were removed. if you ask to free 5, but there are only 3, you will
092     *         get 3.
093     * @throws CacheException
094     */
095    int freeMemoryElements( int numberToFree )
096        throws CacheException;
097
098    /**
099     * This returns the ICacheStats object with information on this region and its auxiliaries.
100     * <p>
101     * This data can be formatted as needed.
102     * <p>
103     * @return ICacheStats
104     */
105    ICacheStats getStatistics();
106
107    /**
108     * @return A String version of the stats.
109     */
110    String getStats();
111}