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 'put' operation.
023 *
024 * @author Costin Leau
025 * @author Phillip Webb
026 * @author Marcin Kamionowski
027 * @since 3.1
028 */
029public class CachePutOperation extends CacheOperation {
030
031        @Nullable
032        private final String unless;
033
034
035        /**
036         * Create a new {@link CachePutOperation} instance from the given builder.
037         * @since 4.3
038         */
039        public CachePutOperation(CachePutOperation.Builder b) {
040                super(b);
041                this.unless = b.unless;
042        }
043
044
045        @Nullable
046        public String getUnless() {
047                return this.unless;
048        }
049
050
051        /**
052         * A builder that can be used to create a {@link CachePutOperation}.
053         * @since 4.3
054         */
055        public static class Builder extends CacheOperation.Builder {
056
057                @Nullable
058                private String unless;
059
060                public void setUnless(String unless) {
061                        this.unless = unless;
062                }
063
064                @Override
065                protected StringBuilder getOperationDescription() {
066                        StringBuilder sb = super.getOperationDescription();
067                        sb.append(" | unless='");
068                        sb.append(this.unless);
069                        sb.append("'");
070                        return sb;
071                }
072
073                @Override
074                public CachePutOperation build() {
075                        return new CachePutOperation(this);
076                }
077        }
078
079}