/** * Create a {@link CacheKeyInvocationContext} based on the specified invocation. * @param context the context of the invocation. * @return the related {@code CacheKeyInvocationContext} */ protected CacheKeyInvocationContext<A> createCacheKeyInvocationContext(CacheOperationInvocationContext<O> context) { return new DefaultCacheKeyInvocationContext<>(context.getOperation(), context.getTarget(), context.getArgs()); }
/** * 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; }
/** * Create a {@link CacheKeyInvocationContext} based on the specified invocation. * @param context the context of the invocation. * @return the related {@code CacheKeyInvocationContext} */ protected CacheKeyInvocationContext<A> createCacheKeyInvocationContext(CacheOperationInvocationContext<O> context) { return new DefaultCacheKeyInvocationContext<>(context.getOperation(), context.getTarget(), context.getArgs()); }
/** * 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; }
@Override protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) { String cls = context.getTarget().getClass().getSimpleName() + (suffix.equals("")?suffix:concat+suffix); return Collections.singletonList(cls); }
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); } }
@Override public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) { List<Cache> caches = new ArrayList<Cache>(); for(String cacheName : context.getOperation().getCacheNames()) { caches.add(cacheManager.getCache(cacheName)); } if(context.getTarget() instanceof UserService2) { caches.add(cacheManager.getCache("user2")); caches.add(cacheManager.getCache("user3")); } return caches; } }
/** * Create a {@link CacheKeyInvocationContext} based on the specified invocation. * @param context the context of the invocation. * @return the related {@code CacheKeyInvocationContext} */ protected CacheKeyInvocationContext<A> createCacheKeyInvocationContext( CacheOperationInvocationContext<O> context) { return new DefaultCacheKeyInvocationContext<A>(context.getOperation(), context.getTarget(), context.getArgs()); }
/** * 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; }