本文整理汇总了Java中org.springframework.cache.interceptor.CacheOperationInvocationContext类的典型用法代码示例。如果您正苦于以下问题:Java CacheOperationInvocationContext类的具体用法?Java CacheOperationInvocationContext怎么用?Java CacheOperationInvocationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheOperationInvocationContext类属于org.springframework.cache.interceptor包,在下文中一共展示了CacheOperationInvocationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private Object execute(CacheOperationInvocationContext<?> context, CacheOperationInvoker invoker) {
CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker);
BasicOperation operation = context.getOperation();
if (operation instanceof CacheResultOperation) {
return cacheResultInterceptor.invoke(
(CacheOperationInvocationContext<CacheResultOperation>) context, adapter);
}
else if (operation instanceof CachePutOperation) {
return cachePutInterceptor.invoke(
(CacheOperationInvocationContext<CachePutOperation>) context, adapter);
}
else if (operation instanceof CacheRemoveOperation) {
return cacheRemoveEntryInterceptor.invoke(
(CacheOperationInvocationContext<CacheRemoveOperation>) context, adapter);
}
else if (operation instanceof CacheRemoveAllOperation) {
return cacheRemoveAllInterceptor.invoke(
(CacheOperationInvocationContext<CacheRemoveAllOperation>) context, adapter);
}
else {
throw new IllegalArgumentException("Could not handle " + operation);
}
}
示例2: invoke
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@Override
protected Object invoke(CacheOperationInvocationContext<CacheRemoveOperation> context,
CacheOperationInvoker invoker) {
CacheRemoveOperation operation = context.getOperation();
final boolean earlyRemove = operation.isEarlyRemove();
if (earlyRemove) {
removeValue(context);
}
try {
Object result = invoker.invoke();
if (!earlyRemove) {
removeValue(context);
}
return result;
}
catch (CacheOperationInvoker.ThrowableWrapper t) {
Throwable ex = t.getOriginal();
if (!earlyRemove && operation.getExceptionTypeFilter().match(ex.getClass())) {
removeValue(context);
}
throw t;
}
}
示例3: getAnnotation
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
private <T extends Annotation> T getAnnotation(CacheOperationInvocationContext<?> context, Class<T> clazz) {
try {
// due to some cache proxy behaviour we can get method of superinterface instead of annotated method from target class
// but sometime annotation has been appear on interface therefore we need check both cases
Method proxiedMethod = context.getMethod();
Class<?> targetClazz = context.getTarget().getClass();
T annotation = null;
if(!targetClazz.equals(proxiedMethod.getDeclaringClass())) {
Method origMethod = targetClazz.getMethod(proxiedMethod.getName(), proxiedMethod.getParameterTypes());
annotation = origMethod.getAnnotation(clazz);
}
if(annotation == null) {
annotation = proxiedMethod.getAnnotation(clazz);
}
return annotation;
} catch (NoSuchMethodException e) {
throw Throwables.asRuntime(e);
}
}
示例4: getCacheNames
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@Override
protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {
String cacheName = (String) context.getArgs()[0];
if (cacheName != null) {
return Collections.singleton(cacheName);
}
return null;
}
示例5: resolveCache
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
/**
* Resolve the cache to use.
* @param context the invocation context
* @return the cache to use (never null)
*/
protected Cache resolveCache(CacheOperationInvocationContext<O> context) {
Collection<? extends Cache> caches = context.getOperation().getCacheResolver().resolveCaches(context);
Cache cache = extractFrom(caches);
if (cache == null) {
throw new IllegalStateException("Cache could not have been resolved for " + context.getOperation());
}
return cache;
}
示例6: createCacheOperationInvocationContext
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private CacheOperationInvocationContext<?> createCacheOperationInvocationContext(
Object target, Object[] args, JCacheOperation<?> operation) {
return new DefaultCacheInvocationContext<Annotation>(
(JCacheOperation<Annotation>) operation, target, args);
}
示例7: invoke
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@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();
cache.put(cacheKey, invocationResult);
return invocationResult;
}
catch (CacheOperationInvoker.ThrowableWrapper ex) {
Throwable original = ex.getOriginal();
cacheException(exceptionCache, operation.getExceptionTypeFilter(), cacheKey, original);
throw ex;
}
}
示例8: resolveExceptionCache
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
private Cache resolveExceptionCache(CacheOperationInvocationContext<CacheResultOperation> context) {
CacheResolver exceptionCacheResolver = context.getOperation().getExceptionCacheResolver();
if (exceptionCacheResolver != null) {
return extractFrom(context.getOperation().getExceptionCacheResolver().resolveCaches(context));
}
return null;
}
示例9: removeValue
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
private void removeValue(CacheOperationInvocationContext<CacheRemoveOperation> context) {
Object key = generateKey(context);
Cache cache = resolveCache(context);
if (logger.isTraceEnabled()) {
logger.trace("Invalidating key [" + key + "] on cache '" + cache.getName()
+ "' for operation " + context.getOperation());
}
doEvict(cache, key);
}
示例10: getCacheNames
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@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;
}
示例11: generateKey
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
/**
* Generate a key for the specified invocation.
* @param context the context of the invocation
* @return the key to use
*/
protected Object generateKey(CacheOperationInvocationContext<O> context) {
KeyGenerator keyGenerator = context.getOperation().getKeyGenerator();
Object key = keyGenerator.generate(context.getTarget(), context.getMethod(), context.getArgs());
if (logger.isTraceEnabled()) {
logger.trace("Computed cache key " + key + " for operation " + context.getOperation());
}
return key;
}
示例12: resolveCaches
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@Override
public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) {
if (this.cacheResolver == null) {
this.cacheResolver = new SimpleExceptionCacheResolver(getDefaultCacheManager());
}
return this.cacheResolver.resolveCaches(context);
}
示例13: invoke
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@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;
}
}
示例14: removeAll
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
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);
}
示例15: resolveCaches
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@Override
public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) {
if (!(context instanceof CacheInvocationContext<?>)) {
throw new IllegalStateException("Unexpected context " + context);
}
CacheInvocationContext<?> cacheInvocationContext = (CacheInvocationContext<?>) context;
javax.cache.Cache<Object, Object> cache = target.resolveCache(cacheInvocationContext);
Assert.notNull(cache, "Cannot resolve cache for '" + context + "' using '" + target + "'");
return Collections.singleton(new JCacheCache(cache));
}