001package org.apache.commons.jcs.engine.behavior; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import org.apache.commons.jcs.access.exception.ObjectExistsException; 023import org.apache.commons.jcs.access.exception.ObjectNotFoundException; 024 025import java.io.IOException; 026import java.util.Map; 027import java.util.Set; 028 029/** 030 * Used to retrieve and update the cache. 031 * <p> 032 * Note: server which implements this interface provides a local cache service, whereas server which 033 * implements IRmiCacheService provides a remote cache service. 034 */ 035public interface ICacheService<K, V> 036{ 037 /** 038 * Puts a cache item to the cache. 039 * <p> 040 * @param item 041 * @throws ObjectExistsException 042 * @throws IOException 043 */ 044 void update( ICacheElement<K, V> item ) 045 throws ObjectExistsException, IOException; 046 047 /** 048 * Returns a cache bean from the specified cache; or null if the key does not exist. 049 * <p> 050 * @param cacheName 051 * @param key 052 * @return the ICacheElement<K, V> or null if not found 053 * @throws ObjectNotFoundException 054 * @throws IOException 055 */ 056 ICacheElement<K, V> get( String cacheName, K key ) 057 throws ObjectNotFoundException, IOException; 058 059 /** 060 * Gets multiple items from the cache based on the given set of keys. 061 * <p> 062 * @param cacheName 063 * @param keys 064 * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no 065 * data in cache for any of these keys 066 * @throws ObjectNotFoundException 067 * @throws IOException 068 */ 069 Map<K, ICacheElement<K, V>> getMultiple( String cacheName, Set<K> keys ) 070 throws ObjectNotFoundException, IOException; 071 072 /** 073 * Gets multiple items from the cache matching the pattern. 074 * <p> 075 * @param cacheName 076 * @param pattern 077 * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no 078 * data in cache matching the pattern. 079 * @throws IOException 080 */ 081 Map<K, ICacheElement<K, V>> getMatching( String cacheName, String pattern ) 082 throws IOException; 083 084 /** 085 * Removes the given key from the specified cache. 086 * <p> 087 * @param cacheName 088 * @param key 089 * @throws IOException 090 */ 091 void remove( String cacheName, K key ) 092 throws IOException; 093 094 /** 095 * Remove all keys from the specified cache. 096 * @param cacheName 097 * @throws IOException 098 */ 099 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}