/** * Check for a cached exception. If the exception is found, throw it directly. */ protected void checkForCachedException(@Nullable Cache exceptionCache, Object cacheKey) { if (exceptionCache == null) { return; } Cache.ValueWrapper result = doGet(exceptionCache, cacheKey); if (result != null) { Throwable ex = (Throwable) result.get(); Assert.state(ex != null, "No exception in cache"); throw rewriteCallStack(ex, getClass().getName(), "invoke"); } }
/** * Check for a cached exception. If the exception is found, throw it directly. */ protected void checkForCachedException(@Nullable Cache exceptionCache, Object cacheKey) { if (exceptionCache == null) { return; } Cache.ValueWrapper result = doGet(exceptionCache, cacheKey); if (result != null) { Throwable ex = (Throwable) result.get(); Assert.state(ex != null, "No exception in cache"); throw rewriteCallStack(ex, getClass().getName(), "invoke"); } }
@Override @Nullable protected Object invoke( CacheOperationInvocationContext<CacheResultOperation> context, CacheOperationInvoker invoker) { CacheResultOperation operation = context.getOperation(); Object cacheKey = generateKey(context); Cache cache = resolveCache(context); Cache exceptionCache = resolveExceptionCache(context); if (!operation.isAlwaysInvoked()) { Cache.ValueWrapper cachedValue = doGet(cache, cacheKey); if (cachedValue != null) { return cachedValue.get(); } checkForCachedException(exceptionCache, cacheKey); } try { Object invocationResult = invoker.invoke(); doPut(cache, cacheKey, invocationResult); return invocationResult; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original); throw ex; } }
@Override @Nullable protected Object invoke( CacheOperationInvocationContext<CacheResultOperation> context, CacheOperationInvoker invoker) { CacheResultOperation operation = context.getOperation(); Object cacheKey = generateKey(context); Cache cache = resolveCache(context); Cache exceptionCache = resolveExceptionCache(context); if (!operation.isAlwaysInvoked()) { Cache.ValueWrapper cachedValue = doGet(cache, cacheKey); if (cachedValue != null) { return cachedValue.get(); } checkForCachedException(exceptionCache, cacheKey); } try { Object invocationResult = invoker.invoke(); doPut(cache, cacheKey, invocationResult); return invocationResult; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original); throw ex; } }
/** * Check for a cached exception. If the exception is found, throw it directly. */ protected void checkForCachedException(Cache exceptionCache, Object cacheKey) { if (exceptionCache == null) { return; } Cache.ValueWrapper result = doGet(exceptionCache, cacheKey); if (result != null) { throw rewriteCallStack((Throwable) result.get(), getClass().getName(), "invoke"); } }
@Override protected Object invoke(CacheOperationInvocationContext<CacheResultOperation> context, CacheOperationInvoker invoker) { CacheResultOperation operation = context.getOperation(); Object cacheKey = generateKey(context); Cache cache = resolveCache(context); Cache exceptionCache = resolveExceptionCache(context); if (!operation.isAlwaysInvoked()) { Cache.ValueWrapper cachedValue = doGet(cache, cacheKey); if (cachedValue != null) { return cachedValue.get(); } checkForCachedException(exceptionCache, cacheKey); } try { Object invocationResult = invoker.invoke(); doPut(cache, cacheKey, invocationResult); return invocationResult; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original); throw ex; } }