001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.cache.interceptor;
018
019/**
020 * Class describing a cache 'evict' operation.
021 *
022 * @author Costin Leau
023 * @author Marcin Kamionowski
024 * @since 3.1
025 */
026public class CacheEvictOperation extends CacheOperation {
027
028        private final boolean cacheWide;
029
030        private final boolean beforeInvocation;
031
032
033        /**
034         * @since 4.3
035         */
036        public CacheEvictOperation(CacheEvictOperation.Builder b) {
037                super(b);
038                this.cacheWide = b.cacheWide;
039                this.beforeInvocation = b.beforeInvocation;
040        }
041
042
043        public boolean isCacheWide() {
044                return this.cacheWide;
045        }
046
047        public boolean isBeforeInvocation() {
048                return this.beforeInvocation;
049        }
050
051
052        /**
053         * @since 4.3
054         */
055        public static class Builder extends CacheOperation.Builder {
056
057                private boolean cacheWide = false;
058
059                private boolean beforeInvocation = false;
060
061                public void setCacheWide(boolean cacheWide) {
062                        this.cacheWide = cacheWide;
063                }
064
065                public void setBeforeInvocation(boolean beforeInvocation) {
066                        this.beforeInvocation = beforeInvocation;
067                }
068
069                @Override
070                protected StringBuilder getOperationDescription() {
071                        StringBuilder sb = super.getOperationDescription();
072                        sb.append(",");
073                        sb.append(this.cacheWide);
074                        sb.append(",");
075                        sb.append(this.beforeInvocation);
076                        return sb;
077                }
078
079                public CacheEvictOperation build() {
080                        return new CacheEvictOperation(this);
081                }
082        }
083
084}