001/* 002 * Copyright 2002-2017 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; 020import org.springframework.lang.Nullable; 021 022/** 023 * A strategy for handling cache-related errors. In most cases, any 024 * exception thrown by the provider should simply be thrown back at 025 * the client but, in some circumstances, the infrastructure may need 026 * to handle cache-provider exceptions in a different way. 027 * 028 * <p>Typically, failing to retrieve an object from the cache with 029 * a given id can be transparently managed as a cache miss by not 030 * throwing back such exception. 031 * 032 * @author Stephane Nicoll 033 * @since 4.1 034 */ 035public interface CacheErrorHandler { 036 037 /** 038 * Handle the given runtime exception thrown by the cache provider when 039 * retrieving an item with the specified {@code key}, possibly 040 * rethrowing it as a fatal exception. 041 * @param exception the exception thrown by the cache provider 042 * @param cache the cache 043 * @param key the key used to get the item 044 * @see Cache#get(Object) 045 */ 046 void handleCacheGetError(RuntimeException exception, Cache cache, Object key); 047 048 /** 049 * Handle the given runtime exception thrown by the cache provider when 050 * updating an item with the specified {@code key} and {@code value}, 051 * possibly rethrowing it as a fatal exception. 052 * @param exception the exception thrown by the cache provider 053 * @param cache the cache 054 * @param key the key used to update the item 055 * @param value the value to associate with the key 056 * @see Cache#put(Object, Object) 057 */ 058 void handleCachePutError(RuntimeException exception, Cache cache, Object key, @Nullable Object value); 059 060 /** 061 * Handle the given runtime exception thrown by the cache provider when 062 * clearing an item with the specified {@code key}, possibly rethrowing 063 * it as a fatal exception. 064 * @param exception the exception thrown by the cache provider 065 * @param cache the cache 066 * @param key the key used to clear the item 067 */ 068 void handleCacheEvictError(RuntimeException exception, Cache cache, Object key); 069 070 /** 071 * Handle the given runtime exception thrown by the cache provider when 072 * clearing the specified {@link Cache}, possibly rethrowing it as a 073 * fatal exception. 074 * @param exception the exception thrown by the cache provider 075 * @param cache the cache to clear 076 */ 077 void handleCacheClearError(RuntimeException exception, Cache cache); 078 079}