/** * 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; }
/** * 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; }
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); } }
/** * 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; }