InvalidateAssignCacheAdvice extends CacheAdvice { @Around("invalidateAssign()") public Object cacheInvalidateAssign(final ProceedingJoinPoint pjp) throws Throwable { if (isDisabled()) { getLogger().info("Cache disabled"); return pjp.proceed(); } final Object result = pjp.proceed(); String cacheKey = null; try { final Method methodToCache = getCacheBase().getMethodToCache(pjp, InvalidateAssignCache.class); final InvalidateAssignCache annotation = methodToCache.getAnnotation(InvalidateAssignCache.class); final AnnotationData data = AnnotationDataBuilder.buildAnnotationData(annotation, InvalidateAssignCache.class, methodToCache); cacheKey = getCacheBase().getCacheKeyBuilder().getAssignCacheKey(data); 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.InvalidateAssignCache)") void invalidateAssign(); @Around("invalidateAssign()") Object cacheInvalidateAssign(final ProceedingJoinPoint pjp);  }
@Test public void valid() throws Throwable { Assume.assumeTrue(isValid); when(pjp.proceed()).thenReturn(expectedValue); assertEquals(expectedValue, advice.cacheInvalidateAssign(pjp)); verify(cache).delete(cacheKey); verify(pjp).proceed(); }