@Test public void testMultipleCachingEval() throws Exception { AnnotatedClass target = new AnnotatedClass(); Method method = ReflectionUtils.findMethod(AnnotatedClass.class, "multipleCaching", Object.class, Object.class); Object[] args = new Object[] { new Object(), new Object() }; Collection<ConcurrentMapCache> caches = Collections.singleton(new ConcurrentMapCache("test")); EvaluationContext evalCtx = eval.createEvaluationContext(caches, method, args, target, target.getClass()); Collection<CacheOperation> ops = getOps("multipleCaching"); Iterator<CacheOperation> it = ops.iterator(); AnnotatedElementKey key = new AnnotatedElementKey(method, AnnotatedClass.class); Object keyA = eval.key(it.next().getKey(), key, evalCtx); Object keyB = eval.key(it.next().getKey(), key, evalCtx); assertEquals(args[0], keyA); assertEquals(args[1], keyB); }
@Override public JCacheOperation<?> getCacheOperation(Method method, Class<?> targetClass) { Object cacheKey = new AnnotatedElementKey(method, targetClass); Object cached = this.cache.get(cacheKey); if (cached != null) { return (cached != NULL_CACHING_ATTRIBUTE ? (JCacheOperation<?>) cached : null); } else { JCacheOperation<?> operation = computeCacheOperation(method, targetClass); if (operation != null) { if (logger.isDebugEnabled()) { logger.debug("Adding cacheable method '" + method.getName() + "' with operation: " + operation); } this.cache.put(cacheKey, operation); } else { this.cache.put(cacheKey, NULL_CACHING_ATTRIBUTE); } return operation; } }
public CacheOperationContext(CacheOperationMetadata metadata, Object[] args, Object target) { this.metadata = metadata; this.args = extractArgs(metadata.method, args); this.target = target; caches = CacheAspectSupport.this.getCaches(this, metadata.cacheResolver); cacheNames = createCacheNames(caches); methodCacheKey = new AnnotatedElementKey(metadata.method, metadata.targetClass); }
/** * Specify if the condition defined by the specified expression matches. */ public boolean condition(String conditionExpression, AnnotatedElementKey elementKey, EvaluationContext evalContext) { return getExpression(this.conditionCache, elementKey, conditionExpression) .getValue(evalContext, boolean.class); }
private Method getTargetMethod(Class<?> targetClass, Method method) { AnnotatedElementKey methodKey = new AnnotatedElementKey(method, targetClass); Method targetMethod = this.targetMethodCache.get(methodKey); if (targetMethod == null) { targetMethod = AopUtils.getMostSpecificMethod(method, targetClass); if (targetMethod == null) { targetMethod = method; } this.targetMethodCache.put(methodKey, targetMethod); } return targetMethod; }
public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method) { this.beanName = beanName; this.method = method; this.targetClass = targetClass; this.bridgedMethod = BridgeMethodResolver.findBridgedMethod(method); this.declaredEventTypes = resolveDeclaredEventTypes(); this.methodKey = new AnnotatedElementKey(this.method, this.targetClass); }
public CacheOperationContext(CacheOperationMetadata metadata, Object[] args, Object target) { this.metadata = metadata; this.args = extractArgs(metadata.method, args); this.target = target; this.caches = CacheAspectSupport.this.getCaches(this, metadata.cacheResolver); this.cacheNames = createCacheNames(this.caches); this.methodCacheKey = new AnnotatedElementKey(metadata.method, metadata.targetClass); }
public LockOperationContext(LockOperationMetadata metadata, Object target, Method method, Object[] args) { this.metadata = metadata; this.args = extractArgs(metadata.getMethod(), args); this.target = target; this.method = method; this.methodCacheKey = new AnnotatedElementKey(metadata.getMethod(), metadata.getTargetClass()); }
private CacheOperationCacheKey(CacheOperation cacheOperation, Method method, Class<?> targetClass) { this.cacheOperation = cacheOperation; methodCacheKey = new AnnotatedElementKey(method, targetClass); }
private CacheOperationCacheKey(CacheOperation cacheOperation, Method method, Class<?> targetClass) { this.cacheOperation = cacheOperation; this.methodCacheKey = new AnnotatedElementKey(method, targetClass); }
public Object key(String keyExpression, AnnotatedElementKey methodKey, EvaluationContext evalContext) { return getExpression(this.keyCache, methodKey, keyExpression).getValue(evalContext); }
public boolean condition(String conditionExpression, AnnotatedElementKey methodKey, EvaluationContext evalContext) { return getExpression(this.conditionCache, methodKey, conditionExpression).getValue(evalContext, boolean.class); }
public boolean unless(String unlessExpression, AnnotatedElementKey methodKey, EvaluationContext evalContext) { return getExpression(this.unlessCache, methodKey, unlessExpression).getValue(evalContext, boolean.class); }
public Object key(String keyExpression, AnnotatedElementKey methodKey, EvaluationContext evalContext) { return getExpression(this.lockCache, methodKey, keyExpression).getValue(evalContext); }
public AnnotatedElementKey getMethodCacheKey() { return methodCacheKey; }
/** * Determine a cache key for the given method and target class. * <p>Must not produce same key for overloaded methods. * Must produce same key for different instances of the same method. * @param method the method (never {@code null}) * @param targetClass the target class (may be {@code null}) * @return the cache key (never {@code null}) */ protected Object getCacheKey(Method method, Class<?> targetClass) { return new AnnotatedElementKey(method, targetClass); }