Top Description Constructors Methods
org.springframework.cache.jcache.interceptor

pack-priv Class CacheResultInterceptor

extends AbstractKeyCacheInterceptor<CacheResultOperation, CacheResult>
Class Inheritance
Annotations
@SuppressWarnings:serial
Imports
javax.cache.annotation.CacheResult, org.springframework.cache.Cache, org.springframework.cache.interceptor.CacheErrorHandler, .CacheOperationInvocationContext, .CacheOperationInvoker, .CacheResolver, org.springframework.lang.Nullable, org.springframework.util.Assert, .ExceptionTypeFilter, .SerializationUtils

Intercept methods annotated with CacheResult.
Author
Stephane Nicoll
Since
4.1

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
cacheException(Cache exceptionCache, ExceptionTypeFilter filter, Object cacheKey, Throwable ex)

protected void
checkForCachedException(Cache exceptionCache, Object cacheKey)

Check for a cached exception.

private static <T extends Throwable> T
cloneException(T exception)

private static int
findCommonAncestorIndex(StackTraceElement[] callStack, String className, String methodName)

protected Object
private Cache
private static CacheOperationInvoker.ThrowableWrapper

Returns:

a clone exception with a rewritten call stack composed of the current call stack up to (included) the common ancestor specified by the className and methodName arguments, followed by stack trace elements of the specified exception after the common ancestor.
rewriteCallStack
(Throwable
the exception to merge with the current call stack
exception
,
String
the class name of the common ancestor
className
,
String
the method name of the common ancestor
methodName
)

Rewrite the call stack of the specified exception so that it matches the current call stack up to (included) the specified method invocation.

Inherited from org.springframework.cache.jcache.interceptor.AbstractKeyCacheInterceptor:
createCacheKeyInvocationContextgenerateKey

Constructor Detail

CacheResultInterceptorback to summary
public CacheResultInterceptor(CacheErrorHandler errorHandler)

Method Detail

cacheExceptionback to summary
protected void cacheException(Cache exceptionCache, ExceptionTypeFilter filter, Object cacheKey, Throwable ex)
checkForCachedExceptionback to summary
protected void checkForCachedException(Cache exceptionCache, Object cacheKey)

Check for a cached exception. If the exception is found, throw it directly.

cloneExceptionback to summary
private static <T extends Throwable> T cloneException(T exception)
Annotations
@Nullable
findCommonAncestorIndexback to summary
private static int findCommonAncestorIndex(StackTraceElement[] callStack, String className, String methodName)
invokeback to summary
protected Object invoke(CacheOperationInvocationContext<CacheResultOperation> context, CacheOperationInvoker invoker)

Implements abstract org.springframework.cache.jcache.interceptor.AbstractCacheInterceptor.invoke.

Annotations
@Override
@Nullable
resolveExceptionCacheback to summary
private Cache resolveExceptionCache(CacheOperationInvocationContext<CacheResultOperation> context)
Annotations
@Nullable
rewriteCallStackback to summary
private static CacheOperationInvoker.ThrowableWrapper rewriteCallStack(Throwable exception, String className, String methodName)

Rewrite the call stack of the specified exception so that it matches the current call stack up to (included) the specified method invocation.

Clone the specified exception. If the exception is not serializable, the original exception is returned. If no common ancestor can be found, returns the original exception.

Used to make sure that a cached exception has a valid invocation context.

Parameters
exception:Throwable

the exception to merge with the current call stack

className:String

the class name of the common ancestor

methodName:String

the method name of the common ancestor

Returns:CacheOperationInvoker.ThrowableWrapper

a clone exception with a rewritten call stack composed of the current call stack up to (included) the common ancestor specified by the className and methodName arguments, followed by stack trace elements of the specified exception after the common ancestor.