001/* 002 * Copyright 2002-2014 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.cache.interceptor; 018 019import org.springframework.cache.Cache; 020 021/** 022 * A strategy for handling cache-related errors. In most cases, any 023 * exception thrown by the provider should simply be thrown back at 024 * the client but, in some circumstances, the infrastructure may need 025 * to handle cache-provider exceptions in a different way. 026 * 027 * <p>Typically, failing to retrieve an object from the cache with 028 * a given id can be transparently managed as a cache miss by not 029 * throwing back such exception. 030 * 031 * @author Stephane Nicoll 032 * @since 4.1 033 */ 034public interface CacheErrorHandler { 035 036 /** 037 * Handle the given runtime exception thrown by the cache provider when 038 * retrieving an item with the specified {@code key}, possibly 039 * rethrowing it as a fatal exception. 040 * @param exception the exception thrown by the cache provider 041 * @param cache the cache 042 * @param key the key used to get the item 043 * @see Cache#get(Object) 044 */ 045 void handleCacheGetError(RuntimeException exception, Cache cache, Object key); 046 047 /** 048 * Handle the given runtime exception thrown by the cache provider when 049 * updating an item with the specified {@code key} and {@code value}, 050 * possibly rethrowing it as a fatal exception. 051 * @param exception the exception thrown by the cache provider 052 * @param cache the cache 053 * @param key the key used to update the item 054 * @param value the value to associate with the key 055 * @see Cache#put(Object, Object) 056 */ 057 void handleCachePutError(RuntimeException exception, Cache cache, Object key, Object value); 058 059 /** 060 * Handle the given runtime exception thrown by the cache provider when 061 * clearing an item with the specified {@code key}, possibly rethrowing 062 * it as a fatal exception. 063 * @param exception the exception thrown by the cache provider 064 * @param cache the cache 065 * @param key the key used to clear the item 066 */ 067 void handleCacheEvictError(RuntimeException exception, Cache cache, Object key); 068 069 /** 070 * Handle the given runtime exception thrown by the cache provider when 071 * clearing the specified {@link Cache}, possibly rethrowing it as a 072 * fatal exception. 073 * @param exception the exception thrown by the cache provider 074 * @param cache the cache to clear 075 */ 076 void handleCacheClearError(RuntimeException exception, Cache cache); 077 078}