Search in sources :

Example 1 with BasicOperation

use of org.springframework.cache.interceptor.BasicOperation in project spring-framework by spring-projects.

the class JCacheAspectSupport method execute.

@SuppressWarnings("unchecked")
private Object execute(CacheOperationInvocationContext<?> context, CacheOperationInvoker invoker) {
    CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker);
    BasicOperation operation = context.getOperation();
    if (operation instanceof CacheResultOperation) {
        return this.cacheResultInterceptor.invoke((CacheOperationInvocationContext<CacheResultOperation>) context, adapter);
    } else if (operation instanceof CachePutOperation) {
        return this.cachePutInterceptor.invoke((CacheOperationInvocationContext<CachePutOperation>) context, adapter);
    } else if (operation instanceof CacheRemoveOperation) {
        return this.cacheRemoveEntryInterceptor.invoke((CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter);
    } else if (operation instanceof CacheRemoveAllOperation) {
        return this.cacheRemoveAllInterceptor.invoke((CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter);
    } else {
        throw new IllegalArgumentException("Cannot handle " + operation);
    }
}
Also used : CacheOperationInvocationContext(org.springframework.cache.interceptor.CacheOperationInvocationContext) BasicOperation(org.springframework.cache.interceptor.BasicOperation) CacheOperationInvoker(org.springframework.cache.interceptor.CacheOperationInvoker)

Example 2 with BasicOperation

use of org.springframework.cache.interceptor.BasicOperation in project spring-framework by spring-projects.

the class SimpleExceptionCacheResolver method getCacheNames.

@Override
protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {
    BasicOperation operation = context.getOperation();
    if (!(operation instanceof CacheResultOperation)) {
        throw new IllegalStateException("Could not extract exception cache name from " + operation);
    }
    CacheResultOperation cacheResultOperation = (CacheResultOperation) operation;
    String exceptionCacheName = cacheResultOperation.getExceptionCacheName();
    if (exceptionCacheName != null) {
        return Collections.singleton(exceptionCacheName);
    }
    return null;
}
Also used : BasicOperation(org.springframework.cache.interceptor.BasicOperation)

Aggregations

BasicOperation (org.springframework.cache.interceptor.BasicOperation)2 CacheOperationInvocationContext (org.springframework.cache.interceptor.CacheOperationInvocationContext)1 CacheOperationInvoker (org.springframework.cache.interceptor.CacheOperationInvoker)1