KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > cache > QueryCache


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19 package org.apache.cayenne.cache;
20
21 import java.util.List JavaDoc;
22
23 import org.apache.cayenne.query.QueryMetadata;
24
25 /**
26  * An interface that defines generic QueryCache.
27  *
28  * @author Andrus Adamchik
29  * @since 3.0
30  */

31 public interface QueryCache {
32
33     /**
34      * Returns a cached query result for the given QueryMetadata or null if the result is
35      * not cached or is expired.
36      */

37     List JavaDoc get(QueryMetadata metadata);
38
39     /**
40      * Returns a cached query result for the given QueryMetadata. If the result is not
41      * cached or is expired, cache will use provided factory to rebuild the value and
42      * store it in the cache. A corollary is that this method never returns null.
43      * <p/>Compared to {@link #get(QueryMetadata)}, this method allows the cache to do
44      * appropriate synchronization when refreshing the entry, preventing multiple threads
45      * from running the same query when a missing entry is requested by multiple threads
46      * simultaneously.
47      */

48     List JavaDoc get(QueryMetadata metadata, QueryCacheEntryFactory factory);
49
50     void put(QueryMetadata metadata, List JavaDoc results);
51
52     /**
53      * Removes a single entry from cache.
54      */

55     void remove(String JavaDoc key);
56
57     /**
58      * Removes a group of entries identified by group key. This may not be supported by
59      * the implementation.
60      */

61     void removeGroup(String JavaDoc groupKey);
62
63     /**
64      * Clears all entries.
65      */

66     void clear();
67
68     int size();
69 }
70
Popular Tags