| 1 | package org.apache.commons.jcs3.engine.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 java.io.IOException; |
| 23 | import java.util.Map; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import org.apache.commons.jcs3.access.exception.ObjectExistsException; |
| 27 | import org.apache.commons.jcs3.access.exception.ObjectNotFoundException; |
| 28 | |
| 29 | /** |
| 30 | * Used to retrieve and update the cache. |
| 31 | * <p> |
| 32 | * Note: server which implements this interface provides a local cache service, whereas server which |
| 33 | * implements IRmiCacheService provides a remote cache service. |
| 34 | */ |
| 35 | public interface ICacheService<K, V> |
| 36 | { |
| 37 | /** |
| 38 | * Puts a cache item to the cache. |
| 39 | * <p> |
| 40 | * @param item |
| 41 | * @throws ObjectExistsException |
| 42 | * @throws IOException |
| 43 | */ |
| 44 | void update( ICacheElement<K, V> item ) |
| 45 | throws ObjectExistsException, IOException; |
| 46 | |
| 47 | /** |
| 48 | * Returns a cache bean from the specified cache; or null if the key does not exist. |
| 49 | * <p> |
| 50 | * @param cacheName |
| 51 | * @param key |
| 52 | * @return the ICacheElement<K, V> or null if not found |
| 53 | * @throws ObjectNotFoundException |
| 54 | * @throws IOException |
| 55 | */ |
| 56 | ICacheElement<K, V> get( String cacheName, K key ) |
| 57 | throws ObjectNotFoundException, IOException; |
| 58 | |
| 59 | /** |
| 60 | * Gets multiple items from the cache based on the given set of keys. |
| 61 | * <p> |
| 62 | * @param cacheName |
| 63 | * @param keys |
| 64 | * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no |
| 65 | * data in cache for any of these keys |
| 66 | * @throws ObjectNotFoundException |
| 67 | * @throws IOException |
| 68 | */ |
| 69 | Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys ) |
| 70 | throws ObjectNotFoundException, IOException; |
| 71 | |
| 72 | /** |
| 73 | * Gets multiple items from the cache matching the pattern. |
| 74 | * <p> |
| 75 | * @param cacheName |
| 76 | * @param pattern |
| 77 | * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no |
| 78 | * data in cache matching the pattern. |
| 79 | * @throws IOException |
| 80 | */ |
| 81 | Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern ) |
| 82 | throws IOException; |
| 83 | |
| 84 | /** |
| 85 | * Removes the given key from the specified cache. |
| 86 | * <p> |
| 87 | * @param cacheName |
| 88 | * @param key |
| 89 | * @throws IOException |
| 90 | */ |
| 91 | void remove( String cacheName, K key ) |
| 92 | throws IOException; |
| 93 | |
| 94 | /** |
| 95 | * Remove all keys from the specified cache. |
| 96 | * @param cacheName |
| 97 | * @throws IOException |
| 98 | */ |
| 99 | void removeAll( String cacheName ) |
| 100 | throws IOException; |
| 101 | |
| 102 | /** |
| 103 | * Frees the specified cache. |
| 104 | * <p> |
| 105 | * @param cacheName |
| 106 | * @throws IOException |
| 107 | */ |
| 108 | void dispose( String cacheName ) |
| 109 | throws IOException; |
| 110 | |
| 111 | /** |
| 112 | * Frees all caches. |
| 113 | * @throws IOException |
| 114 | */ |
| 115 | void release() |
| 116 | throws IOException; |
| 117 | } |