@Test public void valid() throws Throwable { Assume.assumeTrue(isValid); when(pjp.proceed()).thenReturn(expectedValue); assertEquals(expectedValue, advice.cacheInvalidateSingle(pjp)); verify(cache).delete(cacheKey); verify(pjp).proceed(); }
@Around("invalidateSingle()") public Object cacheInvalidateSingle(final ProceedingJoinPoint pjp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return pjp.proceed(); } String cacheKey = null; final AnnotationData data; final Method methodToCache; try { methodToCache = getCacheBase().getMethodToCache(pjp, InvalidateSingleCache.class); final InvalidateSingleCache annotation = methodToCache.getAnnotation(InvalidateSingleCache.class); data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateSingleCache.class, methodToCache); if (!data.isReturnKeyIndex()) { cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, pjp.getArgs(), methodToCache.toString()); } } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); return pjp.proceed(); } final Object result = pjp.proceed(); try { if (data.isReturnKeyIndex()) { getCacheBase().verifyReturnTypeIsNoVoid(methodToCache, InvalidateSingleCache.class); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(result, data.getNamespace()); } getCacheBase().getCache(data).delete(cacheKey); } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); } return result; }
InvalidateSingleCacheAdvice extends CacheAdvice { @Around("invalidateSingle()") public Object cacheInvalidateSingle(final ProceedingJoinPoint pjp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return pjp.proceed(); } String cacheKey = null; final AnnotationData data; final Method methodToCache; try { methodToCache = getCacheBase().getMethodToCache(pjp, InvalidateSingleCache.class); final InvalidateSingleCache annotation = methodToCache.getAnnotation(InvalidateSingleCache.class); data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateSingleCache.class, methodToCache); if (!data.isReturnKeyIndex()) { cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, pjp.getArgs(), methodToCache.toString()); } } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); return pjp.proceed(); } final Object result = pjp.proceed(); try { if (data.isReturnKeyIndex()) { getCacheBase().verifyReturnTypeIsNoVoid(methodToCache, InvalidateSingleCache.class); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(result, data.getNamespace()); } getCacheBase().getCache(data).delete(cacheKey); } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); } return result; } }
InvalidateSingleCacheAdvice extends CacheAdvice { @Around("invalidateSingle()") public Object cacheInvalidateSingle(final ProceedingJoinPoint pjp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return pjp.proceed(); } String cacheKey = null; final AnnotationData data; final Method methodToCache; try { methodToCache = getCacheBase().getMethodToCache(pjp, InvalidateSingleCache.class); final InvalidateSingleCache annotation = methodToCache.getAnnotation(InvalidateSingleCache.class); data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateSingleCache.class, methodToCache); if (!data.isReturnKeyIndex()) { cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, pjp.getArgs(), methodToCache.toString()); } } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); return pjp.proceed(); } final Object result = pjp.proceed(); try { if (data.isReturnKeyIndex()) { getCacheBase().verifyReturnTypeIsNoVoid(methodToCache, InvalidateSingleCache.class); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(result, data.getNamespace()); } getCacheBase().getCache(data).delete(cacheKey); } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); } return result; }  }
InvalidateSingleCacheAdvice extends CacheAdvice { @Around("invalidateSingle()") public Object cacheInvalidateSingle(final ProceedingJoinPoint pjp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return pjp.proceed(); } String cacheKey = null; final AnnotationData data; final Method methodToCache; try { methodToCache = getCacheBase().getMethodToCache(pjp, InvalidateSingleCache.class); final InvalidateSingleCache annotation = methodToCache.getAnnotation(InvalidateSingleCache.class); data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateSingleCache.class, methodToCache); if (!data.isReturnKeyIndex()) { cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, pjp.getArgs(), methodToCache.toString()); } } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); return pjp.proceed(); } final Object result = pjp.proceed(); try { if (data.isReturnKeyIndex()) { getCacheBase().verifyReturnTypeIsNoVoid(methodToCache, InvalidateSingleCache.class); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(result, data.getNamespace()); } getCacheBase().getCache(data).delete(cacheKey); } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); } return result; }  @Pointcut("@annotation(com.google.code.ssm.api.InvalidateSingleCache)") void invalidateSingle(); @Around("invalidateSingle()") Object cacheInvalidateSingle(final ProceedingJoinPoint pjp); }
InvalidateSingleCacheAdvice extends CacheAdvice { @Around("invalidateSingle()") public Object cacheInvalidateSingle(final ProceedingJoinPoint pjp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return pjp.proceed(); } String cacheKey = null; final AnnotationData data; final Method methodToCache; try { methodToCache = getCacheBase().getMethodToCache(pjp, InvalidateSingleCache.class); final InvalidateSingleCache annotation = methodToCache.getAnnotation(InvalidateSingleCache.class); data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateSingleCache.class, methodToCache); if (!data.isReturnKeyIndex()) { cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, pjp.getArgs(), methodToCache.toString()); } } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); return pjp.proceed(); } final Object result = pjp.proceed(); try { if (data.isReturnKeyIndex()) { getCacheBase().verifyReturnTypeIsNoVoid(methodToCache, InvalidateSingleCache.class); cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(result, data.getNamespace()); } getCacheBase().getCache(data).delete(cacheKey); } catch (Exception ex) { warn(ex, "Caching on method %s and key [%s] aborted due to an error.", pjp.toShortString(), cacheKey); } return result; }  @Pointcut("@annotation(com.google.code.ssm.api.InvalidateSingleCache)") void invalidateSingle(); @Around("invalidateSingle()") Object cacheInvalidateSingle(final ProceedingJoinPoint pjp);  }