Example usage for org.springframework.cache.interceptor CacheEvictOperation isBeforeInvocation

List of usage examples for org.springframework.cache.interceptor CacheEvictOperation isBeforeInvocation

Introduction

In this page you can find the example usage for org.springframework.cache.interceptor CacheEvictOperation isBeforeInvocation.

Prototype

public boolean isBeforeInvocation() 

Source Link

Usage

From source file:grails.plugin.cache.web.filter.PageFragmentCachingFilter.java

protected boolean inspectCacheEvicts(Collection<CacheOperationContext> evictions, boolean beforeInvocation) {
    if (evictions.isEmpty()) {
        return false;
    }//w  ww .j a  va 2  s. c  om

    boolean trace = log.isTraceEnabled();

    boolean atLeastOne = false;
    for (CacheOperationContext operationContext : evictions) {
        CacheEvictOperation evict = (CacheEvictOperation) operationContext.operation;

        if (beforeInvocation == evict.isBeforeInvocation()) {
            if (operationContext.isConditionPassing()) {
                atLeastOne = true;
                // for each cache
                // lazy key initialization
                Object key = null;

                for (Cache cache : operationContext.getCaches()) {
                    // cache-wide flush
                    if (evict.isCacheWide()) {
                        cache.clear();
                        logRequestDetails(operationContext.request, getContext(), "Flushing request");
                    } else {
                        // check key
                        if (key == null) {
                            key = operationContext.generateKey();
                        }
                        if (trace) {
                            log.trace("Invalidating cache key {} for operation {} on method {}",
                                    new Object[] { key, evict, operationContext.method });
                        }
                        cache.evict(key);
                    }
                }
            } else {
                logRequestDetails(operationContext.request, getContext(), "Not flushing request");
            }
        }
    }
    return atLeastOne;
}

From source file:org.springframework.cache.interceptor.CacheAspectSupport.java

private void processCacheEvicts(Collection<CacheOperationContext> contexts, boolean beforeInvocation,
        @Nullable Object result) {

    for (CacheOperationContext context : contexts) {
        CacheEvictOperation operation = (CacheEvictOperation) context.metadata.operation;
        if (beforeInvocation == operation.isBeforeInvocation() && isConditionPassing(context, result)) {
            performCacheEvict(context, operation, result);
        }//from ww w  .java 2  s . co m
    }
}

From source file:org.springframework.cache.interceptor.YJFCacheAspectSupport.java

private void inspectCacheEvicts(Collection<CacheOperationContext> evictions, boolean beforeInvocation) {

    if (!evictions.isEmpty()) {

        boolean log = logger.isTraceEnabled();

        for (CacheOperationContext context : evictions) {
            CacheEvictOperation evictOp = (CacheEvictOperation) context.operation;

            if (beforeInvocation == evictOp.isBeforeInvocation()) {
                if (context.isConditionPassing()) {
                    // for each cache
                    // lazy key initialization
                    Object key = null;

                    for (Cache cache : context.getCaches()) {
                        // cache-wide flush
                        if (evictOp.isCacheWide()) {
                            cache.clear();
                            if (log) {
                                logger.trace("Invalidating entire cache for operation " + evictOp
                                        + " on method " + context.method);
                            }/*  w  w  w.j a va  2  s.co  m*/
                        } else {
                            // check key
                            if (key == null) {
                                key = context.generateKey();
                            }
                            if (log) {
                                logger.trace("Invalidating cache key " + key + " for operation " + evictOp
                                        + " on method " + context.method);
                            }
                            cache.evict(key);
                        }
                    }
                } else {
                    if (log) {
                        logger.trace("Cache condition failed on method " + context.method + " for operation "
                                + context.operation);
                    }
                }
            }
        }
    }
}