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 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 * Create a new {@link CacheEvictOperation} instance from the given builder. 035 * @since 4.3 036 */ 037 public CacheEvictOperation(CacheEvictOperation.Builder b) { 038 super(b); 039 this.cacheWide = b.cacheWide; 040 this.beforeInvocation = b.beforeInvocation; 041 } 042 043 044 public boolean isCacheWide() { 045 return this.cacheWide; 046 } 047 048 public boolean isBeforeInvocation() { 049 return this.beforeInvocation; 050 } 051 052 053 /** 054 * A builder that can be used to create a {@link CacheEvictOperation}. 055 * @since 4.3 056 */ 057 public static class Builder extends CacheOperation.Builder { 058 059 private boolean cacheWide = false; 060 061 private boolean beforeInvocation = false; 062 063 public void setCacheWide(boolean cacheWide) { 064 this.cacheWide = cacheWide; 065 } 066 067 public void setBeforeInvocation(boolean beforeInvocation) { 068 this.beforeInvocation = beforeInvocation; 069 } 070 071 @Override 072 protected StringBuilder getOperationDescription() { 073 StringBuilder sb = super.getOperationDescription(); 074 sb.append(","); 075 sb.append(this.cacheWide); 076 sb.append(","); 077 sb.append(this.beforeInvocation); 078 return sb; 079 } 080 081 @Override 082 public CacheEvictOperation build() { 083 return new CacheEvictOperation(this); 084 } 085 } 086 087}