1 /**
2 * Copyright 2003-2007 Greg Luck
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 at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * 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 and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.store;
18
19 import java.io.IOException;
20
21 import net.sf.ehcache.CacheException;
22 import net.sf.ehcache.Element;
23 import net.sf.ehcache.Status;
24
25 /**
26 * This is the interface for all stores. A store is a physical counterpart to a cache, which
27 * is a logical concept.
28 *
29 * @author Greg Luck
30 * @version $Id: Store.java 512 2007-07-10 09:18:45Z gregluck $
31 */
32 public interface Store {
33
34 /**
35 * Puts an item into the cache.
36 */
37 void put(Element element) throws CacheException;
38
39 /**
40 * Gets an item from the cache.
41 */
42 Element get(Object key);
43
44 /**
45 * Gets an {@link Element} from the Disk Store, without updating statistics
46 *
47 * @return The element
48 */
49 public Element getQuiet(final Object key);
50
51 /**
52 * Gets an Array of the keys for all elements in the disk store.
53 *
54 * @return An Object[] of {@link java.io.Serializable} keys
55 * @noinspection SynchronizeOnNonFinalField
56 */
57 public Object[] getKeyArray();
58
59 /**
60 * Removes an item from the cache.
61 *
62 * @since signature changed in 1.2 from boolean to Element to support notifications
63 */
64 Element remove(Object key);
65
66 /**
67 * Remove all of the elements from the store.
68 * <p/>
69 * If there are registered <code>CacheEventListener</code>s they are notified of the expiry or removal
70 * of the <code>Element</code> as each is removed.
71 */
72 void removeAll() throws CacheException;
73
74 /**
75 * Prepares for shutdown.
76 */
77 void dispose();
78
79 /**
80 * Returns the current store size.
81 */
82 int getSize();
83
84 /**
85 * Returns the cache status.
86 */
87 Status getStatus();
88
89
90 /**
91 * A check to see if a key is in the Store.
92 *
93 * @param key The Element key
94 * @return true if found. No check is made to see if the Element is expired.
95 * 1.2
96 */
97 boolean containsKey(Object key);
98
99 /**
100 * Expire all elements.
101 */
102 public void expireElements();
103
104 /**
105 * Flush elements to persistent store.
106 * @throws IOException if any IO error occurs
107 */
108 public void flush() throws IOException;
109
110 /**
111 * Some store types, such as the disk stores can get backed up
112 * when puts come in to fast.
113 * @return true if the store is backed up.
114 */
115 public boolean backedUp();
116
117 }