View Javadoc

1   package org.apache.jcs.access.behavior;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "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 org.apache.jcs.access.exception.CacheException;
23  import org.apache.jcs.engine.behavior.ICompositeCacheAttributes;
24  import org.apache.jcs.engine.behavior.IElementAttributes;
25  
26  /***
27   * ICacheAccess defines the behavior for client access.
28   */
29  public interface ICacheAccess
30  {
31      /***
32       * Basic get method.
33       * <p>
34       * @param name
35       * @return Object or null if not found.
36       */
37      Object get( Object name );
38  
39      /***
40       * Puts in cache if an item does not exist with the name in that region.
41       * <p>
42       * @param name
43       * @param obj
44       * @throws CacheException
45       */
46      void putSafe( Object name, Object obj )
47          throws CacheException;
48  
49      /***
50       * Puts and/or overides an element with the name in that region.
51       * <p>
52       * @param name
53       * @param obj
54       * @throws CacheException
55       */
56      void put( Object name, Object obj )
57          throws CacheException;
58  
59      /***
60       * Description of the Method
61       * <p>
62       * @param name
63       * @param obj
64       * @param attr
65       * @throws CacheException
66       */
67      void put( Object name, Object obj, IElementAttributes attr )
68          throws CacheException;
69  
70      /***
71       * Removes an item or all items. Should be called remove.
72       * <p>
73       * @throws CacheException
74       * @deprecated
75       * @see #remove
76       */
77      void destroy()
78          throws CacheException;
79  
80      /***
81       * Old remove all method.
82       * @throws CacheException
83       */
84      void remove()
85          throws CacheException;
86  
87      /***
88       * The older removeall method.
89       * <p>
90       * @param name
91       * @throws CacheException
92       * @deprecated
93       * @see #remove
94       */
95      void destroy( Object name )
96          throws CacheException;
97  
98      /***
99       * Remove an object for this key if one exists, else do nothing.
100      * <p>
101      * @param name
102      * @throws CacheException
103      */
104     void remove( Object name )
105         throws CacheException;
106 
107     /***
108      * ResetAttributes allows for some of the attributes of a region to be reset
109      * in particular expiration time attriubtes, time to live, default time to
110      * live and idle time, and event handlers. The cacheloader object and
111      * attributes set as flags can't be reset with resetAttributes, the object
112      * must be destroyed and redefined to cache those parameters. Changing
113      * default settings on groups and regions will not affect existing objects.
114      * Only object loaded after the reset will use the new defaults. If no name
115      * argument is provided, the reset is applied to the region.
116      * <p>
117      * @param attr
118      * @throws CacheException
119      */
120     void resetElementAttributes( IElementAttributes attr )
121         throws CacheException;
122 
123     /***
124      * Reset the attributes on the object matching this key name.
125      * <p>
126      * @param name
127      * @param attr
128      * @throws CacheException
129      */
130     void resetElementAttributes( Object name, IElementAttributes attr )
131         throws CacheException;
132 
133     /***
134      * GetElementAttributes will return an attribute object describing the
135      * current attributes associated with the object name. If no name parameter
136      * is available, the attributes for the region will be returned. The name
137      * object must override the Object.equals and Object.hashCode methods.
138      * <p>
139      * @return The elementAttributes value
140      * @throws CacheException
141      */
142     IElementAttributes getElementAttributes()
143         throws CacheException;
144 
145     /***
146      * Gets the elementAttributes attribute of the ICacheAccess object
147      * <p>
148      * @param name
149      * @return The elementAttributes value
150      * @throws CacheException
151      */
152     IElementAttributes getElementAttributes( Object name )
153         throws CacheException;
154 
155     /***
156      * Gets the ICompositeCacheAttributes of the cache region
157      * <p>
158      * @return ICompositeCacheAttributes
159      */
160     public ICompositeCacheAttributes getCacheAttributes();
161 
162     /***
163      * Sets the ICompositeCacheAttributes of the cache region
164      * <p>
165      * @param cattr
166      *            The new ICompositeCacheAttribute value
167      */
168     public void setCacheAttributes( ICompositeCacheAttributes cattr );
169 
170     /***
171      * This instructs the memory cache to remove the <i>numberToFree</i>
172      * according to its eviction policy. For example, the LRUMemoryCache will
173      * remove the <i>numberToFree</i> least recently used items. These will be
174      * spooled to disk if a disk auxiliary is available.
175      * <p>
176      * @param numberToFree
177      * @return the number that were removed. if you ask to free 5, but there are
178      *         only 3, you will get 3.
179      * @throws CacheException
180      */
181     public int freeMemoryElements( int numberToFree )
182         throws CacheException;
183 }