本文整理汇总了Java中org.springframework.cache.interceptor.CacheOperationInvocationContext类的典型用法代码示例。如果您正苦于以下问题:Java CacheOperationInvocationContext类的具体用法?Java CacheOperationInvocationContext怎么用?Java CacheOperationInvocationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheOperationInvocationContext类属于org.springframework.cache.interceptor包,在下文中一共展示了CacheOperationInvocationContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:JCacheAspectSupport.java
示例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;
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:CacheRemoveEntryInterceptor.java
示例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);
}
}
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:20,代码来源:ConfigurableCacheResolver.java
示例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;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:CacheReproTests.java
示例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;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:AbstractCacheInterceptor.java
示例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);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:JCacheAspectSupport.java
示例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;
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:CacheResultInterceptor.java
示例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;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:CacheResultInterceptor.java
示例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);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:CacheRemoveEntryInterceptor.java
示例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;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:SimpleExceptionCacheResolver.java
示例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;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:AbstractKeyCacheInterceptor.java
示例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);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:8,代码来源:DefaultJCacheOperationSource.java
示例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;
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:28,代码来源:CacheRemoveAllInterceptor.java
示例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);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:CacheRemoveAllInterceptor.java
示例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));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:CacheResolverAdapter.java
示例16: invoke
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@Override
protected Object invoke(CacheOperationInvocationContext<CachePutOperation> context,
CacheOperationInvoker invoker) {
CacheKeyInvocationContext<CachePut> invocationContext = createCacheKeyInvocationContext(context);
CachePutOperation operation = context.getOperation();
boolean earlyPut = operation.isEarlyPut();
Object value = invocationContext.getValueParameter().getValue();
if (earlyPut) {
cacheValue(context, value);
}
try {
Object result = invoker.invoke();
if (!earlyPut) {
cacheValue(context, value);
}
return result;
}
catch (CacheOperationInvoker.ThrowableWrapper ex) {
Throwable original = ex.getOriginal();
if (!earlyPut && operation.getExceptionTypeFilter().match(original.getClass())) {
cacheValue(context, value);
}
throw ex;
}
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:CachePutInterceptor.java
示例17: resolveCaches
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@Override
public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) {
List<Cache> caches = new ArrayList<Cache>();
for (String cacheName : context.getOperation().getCacheNames()) {
caches.add(cacheManager.getCache(coreConfig.getCtx()+Constants.COLON+cacheName));
}
return caches;
}
开发者ID:simbest,项目名称:simbest-cores,代码行数:9,代码来源:GenericCacheResolver.java
示例18: cacheResolver
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@Override
@Bean
// The @Bean annotation is important, see CachingConfigurerSupport Javadoc
public CacheResolver cacheResolver() {
return new CacheResolver() {
@Override
public Collection<? extends Cache> resolveCaches(
CacheOperationInvocationContext<?> context) {
return Collections.singleton(mock(Cache.class));
}
};
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:16,代码来源:CacheAutoConfigurationTests.java
示例19: getCacheNames
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
@Override
protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) {
String cls = context.getTarget().getClass().getSimpleName()
+ (suffix.equals("")?suffix:concat+suffix);
return Collections.singletonList(cls);
}
开发者ID:quebic-source,项目名称:microservices-sample-project,代码行数:7,代码来源:ClassNameBasedCacheResolver.java
示例20: invoke
import org.springframework.cache.interceptor.CacheOperationInvocationContext; //导入依赖的package包/类
protected abstract Object invoke(CacheOperationInvocationContext<O> context, CacheOperationInvoker invoker)
throws Throwable;
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:3,代码来源:AbstractCacheInterceptor.java
注:本文中的org.springframework.cache.interceptor.CacheOperationInvocationContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论