001/*
002 * Copyright 2002-2018 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
019import org.springframework.lang.Nullable;
020
021/**
022 * Class describing a cache 'cacheable' operation.
023 *
024 * @author Costin Leau
025 * @author Phillip Webb
026 * @author Marcin Kamionowski
027 * @since 3.1
028 */
029public class CacheableOperation extends CacheOperation {
030
031        @Nullable
032        private final String unless;
033
034        private final boolean sync;
035
036
037        /**
038         * Create a new {@link CacheableOperation} instance from the given builder.
039         * @since 4.3
040         */
041        public CacheableOperation(CacheableOperation.Builder b) {
042                super(b);
043                this.unless = b.unless;
044                this.sync = b.sync;
045        }
046
047
048        @Nullable
049        public String getUnless() {
050                return this.unless;
051        }
052
053        public boolean isSync() {
054                return this.sync;
055        }
056
057
058        /**
059         * A builder that can be used to create a {@link CacheableOperation}.
060         * @since 4.3
061         */
062        public static class Builder extends CacheOperation.Builder {
063
064                @Nullable
065                private String unless;
066
067                private boolean sync;
068
069                public void setUnless(String unless) {
070                        this.unless = unless;
071                }
072
073                public void setSync(boolean sync) {
074                        this.sync = sync;
075                }
076
077                @Override
078                protected StringBuilder getOperationDescription() {
079                        StringBuilder sb = super.getOperationDescription();
080                        sb.append(" | unless='");
081                        sb.append(this.unless);
082                        sb.append("'");
083                        sb.append(" | sync='");
084                        sb.append(this.sync);
085                        sb.append("'");
086                        return sb;
087                }
088
089                @Override
090                public CacheableOperation build() {
091                        return new CacheableOperation(this);
092                }
093        }
094
095}