KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > whirlycott > cache > Cache


1 /*
2 Copyright 2004 Philip Jacob <phil@whirlycott.com>
3                     Seth Fitzsimmons <seth@note.amherst.edu>
4
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8
9     http://www.apache.org/licenses/LICENSE-2.0
10
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 */

17
18
19 package com.whirlycott.cache;
20
21
22 /**
23  * Defines a simple interface that all caches should implement.
24  * @author phil
25  */

26 public interface Cache {
27     
28     /**
29      * Retrieve an object from the cache.
30      * @param key key associated with desired object.
31      * @return object identified by provided key.
32      */

33     public Object JavaDoc retrieve(Object JavaDoc key);
34     
35     
36     /**
37      * Retrieve an object whose key implements Cacheable. The onRetrieve() method will
38      * be executed here.
39      * @param key
40      * @return the object retrieved from the cache.
41      */

42     public Object JavaDoc retrieve(Cacheable key);
43     
44     /**
45      * Store an object in the cache.
46      * @param key key associated with object to store.
47      * @param value object identified by provided key.
48      */

49     public void store(Object JavaDoc key, Object JavaDoc value);
50     
51     /**
52      * Store an object in the cache with a Cacheable key.
53      * The onStore() method will be executed here.
54      * @param key
55      * @param value
56      */

57     public void store(Cacheable key, Object JavaDoc value);
58
59     /**
60      * Store an object in the cache.
61      * @param key - the key to retrieve the object later.
62      * @param value - the object to be cached.
63      * @param expireTime - milliseconds that this item should be kept in the cache
64      * (accurate to <code>tuner-sleeptime</code> seconds, as specified in <code>whirlycache.xml</code>.
65      */

66     public void store(Object JavaDoc key, Object JavaDoc value, long expireTime);
67     
68     /**
69      * Store an object in the cache with a Cacheable key. The onStore() method is
70      * execute here.
71      * @param key - the key to retrieve the object later.
72      * @param value - the object to be cached.
73      * @param expireTime - milliseconds that this item should be kept in the cache
74      * (accurate to <code>tuner-sleeptime</code> seconds, as specified in <code>whirlycache.xml</code>.
75      */

76     public void store(Cacheable key, Object JavaDoc value, long expireTime);
77     
78     /**
79      * Remove an object from the cache.
80      * @param key key associated with object to remove.
81      * @return object that was removed.
82      */

83     public Object JavaDoc remove(Object JavaDoc key);
84     
85     /**
86      * Removes an object from the cache and executes the onRemove() method.
87      * @param key
88      * @return object that was removed
89      */

90     public Object JavaDoc remove(Cacheable key);
91     
92     /**
93      * Clear the cache.
94      */

95     public void clear();
96     
97     /**
98      * Get the current size of the cache.
99      */

100     public int size();
101         
102 }
103
Popular Tags