protected void removeAll(CacheOperationInvocationContext<CacheRemoveAllOperation> context) { Cache cache = resolveCache(context); if (logger.isTraceEnabled()) { logger.trace("Invalidating entire cache '" + cache.getName() + "' for operation " + context.getOperation()); } doClear(cache); }
@SuppressWarnings("unchecked") @Nullable private Object execute(CacheOperationInvocationContext<?> context, CacheOperationInvoker invoker) { CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker); BasicOperation operation = context.getOperation(); if (operation instanceof CacheResultOperation) { Assert.state(this.cacheResultInterceptor != null, "No CacheResultInterceptor"); return this.cacheResultInterceptor.invoke( (CacheOperationInvocationContext<CacheResultOperation>) context, adapter); } else if (operation instanceof CachePutOperation) { Assert.state(this.cachePutInterceptor != null, "No CachePutInterceptor"); return this.cachePutInterceptor.invoke( (CacheOperationInvocationContext<CachePutOperation>) context, adapter); } else if (operation instanceof CacheRemoveOperation) { Assert.state(this.cacheRemoveEntryInterceptor != null, "No CacheRemoveEntryInterceptor"); return this.cacheRemoveEntryInterceptor.invoke( (CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter); } else if (operation instanceof CacheRemoveAllOperation) { Assert.state(this.cacheRemoveAllInterceptor != null, "No CacheRemoveAllInterceptor"); return this.cacheRemoveAllInterceptor.invoke( (CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter); } else { throw new IllegalArgumentException("Cannot handle " + operation); } }
@Override protected Object invoke( CacheOperationInvocationContext<CacheRemoveAllOperation> context, CacheOperationInvoker invoker) { CacheRemoveAllOperation operation = context.getOperation(); boolean earlyRemove = operation.isEarlyRemove(); if (earlyRemove) { removeAll(context); } try { Object result = invoker.invoke(); if (!earlyRemove) { removeAll(context); } return result; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); if (!earlyRemove && operation.getExceptionTypeFilter().match(original.getClass())) { removeAll(context); } throw ex; } }
public void afterPropertiesSet() { getCacheOperationSource(); this.cacheResultInterceptor = new CacheResultInterceptor(getErrorHandler()); this.cachePutInterceptor = new CachePutInterceptor(getErrorHandler()); this.cacheRemoveEntryInterceptor = new CacheRemoveEntryInterceptor(getErrorHandler()); this.cacheRemoveAllInterceptor = new CacheRemoveAllInterceptor(getErrorHandler()); this.initialized = true; }
public void afterPropertiesSet() { getCacheOperationSource(); this.cacheResultInterceptor = new CacheResultInterceptor(getErrorHandler()); this.cachePutInterceptor = new CachePutInterceptor(getErrorHandler()); this.cacheRemoveEntryInterceptor = new CacheRemoveEntryInterceptor(getErrorHandler()); this.cacheRemoveAllInterceptor = new CacheRemoveAllInterceptor(getErrorHandler()); this.initialized = true; }
protected void removeAll(CacheOperationInvocationContext<CacheRemoveAllOperation> context) { Cache cache = resolveCache(context); if (logger.isTraceEnabled()) { logger.trace("Invalidating entire cache '" + cache.getName() + "' for operation " + context.getOperation()); } doClear(cache); }
public void afterPropertiesSet() { Assert.state(getCacheOperationSource() != null, "The 'cacheOperationSource' property is required: " + "If there are no cacheable methods, then don't use a cache aspect."); Assert.state(getErrorHandler() != null, "The 'errorHandler' property is required"); this.cacheResultInterceptor = new CacheResultInterceptor(getErrorHandler()); this.cachePutInterceptor = new CachePutInterceptor(getErrorHandler()); this.cacheRemoveEntryInterceptor = new CacheRemoveEntryInterceptor(getErrorHandler()); this.cacheRemoveAllInterceptor = new CacheRemoveAllInterceptor(getErrorHandler()); this.initialized = true; }
@Override protected Object invoke( CacheOperationInvocationContext<CacheRemoveAllOperation> context, CacheOperationInvoker invoker) { CacheRemoveAllOperation operation = context.getOperation(); boolean earlyRemove = operation.isEarlyRemove(); if (earlyRemove) { removeAll(context); } try { Object result = invoker.invoke(); if (!earlyRemove) { removeAll(context); } return result; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); if (!earlyRemove && operation.getExceptionTypeFilter().match(original.getClass())) { removeAll(context); } throw ex; } }
@SuppressWarnings("unchecked") @Nullable private Object execute(CacheOperationInvocationContext<?> context, CacheOperationInvoker invoker) { CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker); BasicOperation operation = context.getOperation(); if (operation instanceof CacheResultOperation) { Assert.state(this.cacheResultInterceptor != null, "No CacheResultInterceptor"); return this.cacheResultInterceptor.invoke( (CacheOperationInvocationContext<CacheResultOperation>) context, adapter); } else if (operation instanceof CachePutOperation) { Assert.state(this.cachePutInterceptor != null, "No CachePutInterceptor"); return this.cachePutInterceptor.invoke( (CacheOperationInvocationContext<CachePutOperation>) context, adapter); } else if (operation instanceof CacheRemoveOperation) { Assert.state(this.cacheRemoveEntryInterceptor != null, "No CacheRemoveEntryInterceptor"); return this.cacheRemoveEntryInterceptor.invoke( (CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter); } else if (operation instanceof CacheRemoveAllOperation) { Assert.state(this.cacheRemoveAllInterceptor != null, "No CacheRemoveAllInterceptor"); return this.cacheRemoveAllInterceptor.invoke( (CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter); } else { throw new IllegalArgumentException("Cannot handle " + operation); } }
protected void removeAll(CacheOperationInvocationContext<CacheRemoveAllOperation> context) { Cache cache = resolveCache(context); if (logger.isTraceEnabled()) { logger.trace("Invalidating entire cache '" + cache.getName() + "' for operation " + context.getOperation()); } doClear(cache); }
@Override protected Object invoke(CacheOperationInvocationContext<CacheRemoveAllOperation> context, CacheOperationInvoker invoker) { CacheRemoveAllOperation operation = context.getOperation(); boolean earlyRemove = operation.isEarlyRemove(); if (earlyRemove) { removeAll(context); } try { Object result = invoker.invoke(); if (!earlyRemove) { removeAll(context); } return result; } catch (CacheOperationInvoker.ThrowableWrapper ex) { Throwable original = ex.getOriginal(); if (!earlyRemove && operation.getExceptionTypeFilter().match(original.getClass())) { removeAll(context); } throw ex; } }
/** * Execute the underlying operation (typically in case of cache miss) and return * the result of the invocation. If an exception occurs it will be wrapped in * a {@code ThrowableWrapper}: the exception can be handled or modified but it * <em>must</em> be wrapped in a {@code ThrowableWrapper} as well. * @param invoker the invoker handling the operation being cached * @return the result of the invocation * @see CacheOperationInvoker#invoke() */ protected Object invokeOperation(CacheOperationInvoker invoker) { return invoker.invoke(); }