class InvalidateSingleCacheAdvice extends CacheAdvice {

    @Around("invalidateSingle()")
    public Object cacheInvalidateSingle(final ProceedingJoinPoint pjp) throws Throwable {
        if (isDisabled()) {
            getLogger().info("Cache disabled");
            return pjp.proceed();
        }

        // This is injected caching. If anything goes wrong in the caching, LOG
        // the crap outta it, but do not let it surface up past the AOP injection itself.
        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();

        // This is injected caching. If anything goes wrong in the caching, LOG
        // the crap outta it, but do not let it surface up past the AOP injection itself.
        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;
    }

}