class UpdateCounterInCacheAdvice extends CounterInCacheBase {

    @AfterReturning(pointcut = "updateCounter()", returning = "retVal")
    public void cacheCounterInCache(final JoinPoint jp, final Object retVal) throws Throwable {
        if (isDisabled()) {
            getLogger().info("Cache disabled");
            return;
        }

        // For Update*Cache, an AfterReturning aspect is fine. We will only
        // apply our caching after the underlying method completes successfully, and we will have
        // the same access to the method params.
        String cacheKey = null;
        UpdateCounterInCache annotation;
        try {
            Method methodToCache = getCacheBase().getMethodToCache(jp, UpdateCounterInCache.class);
            annotation = methodToCache.getAnnotation(UpdateCounterInCache.class);
            AnnotationData data = AnnotationDataBuilder.buildAnnotationData(annotation, UpdateCounterInCache.class, methodToCache);
            cacheKey = getCacheBase().getCacheKeyBuilder().getCacheKey(data, jp.getArgs(), methodToCache.toString());

            Object dataObject = getCacheBase().getUpdateData(data, methodToCache, jp.getArgs(), retVal);
            if (checkData(dataObject, jp)) {
                long value = ((Number) dataObject).longValue();
                getCacheBase().getCache(data).setCounter(cacheKey, annotation.expiration(), value);
            }
        } catch (Exception ex) {
            warn(ex, "Updating counter [%s] in cache via %s aborted due to an error.", cacheKey, jp.toShortString());
        }
    }

}