92df65ec26d31f1bf02ce597d3685d3cceb96225
[utils] / support / general / src / main / java / org / wamblee / cache / Cache.java
1 /*
2  * Copyright 2005 the original author or authors.
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 package org.wamblee.cache;
17
18 import java.io.Serializable;
19
20
21 /**
22  * The <code>Cache</code> interface represents... a cache.
23  * In some circumstances it is more optimal to implement caching directly in
24  * the code instead of relying on Hibernate caching methods. This interface abstracts
25  * from the used cache implementation.
26  * Cache implementations must be thread-safe.
27  */
28 public interface Cache<KeyType extends Serializable, ValueType extends Serializable> {
29     /**
30      * Adds a key-value pair to the cache.
31      *
32      * @param aKey Key.
33      * @param aValue Value.
34      */
35     void put(KeyType aKey, ValueType aValue);
36
37     /**
38      * Retrieves a value from the cache.
39      *
40      * @param aKey Key to retrieve.
41      *
42      * @return Key.
43      */
44     ValueType get(KeyType aKey);
45
46     /**
47      * Removes an entry from the cache.
48      *
49      * @param aKey Key to remove the entry for.
50      */
51     void remove(KeyType aKey);
52
53     /**
54      * Removes all entries from the cache.
55      */
56     void clear();
57 }