001/* 002 * Copyright 2002-2017 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.aop.ClassFilter; 020import org.springframework.aop.Pointcut; 021import org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor; 022import org.springframework.lang.Nullable; 023 024/** 025 * Advisor driven by a {@link CacheOperationSource}, used to include a 026 * cache advice bean for methods that are cacheable. 027 * 028 * @author Costin Leau 029 * @since 3.1 030 */ 031@SuppressWarnings("serial") 032public class BeanFactoryCacheOperationSourceAdvisor extends AbstractBeanFactoryPointcutAdvisor { 033 034 @Nullable 035 private CacheOperationSource cacheOperationSource; 036 037 private final CacheOperationSourcePointcut pointcut = new CacheOperationSourcePointcut() { 038 @Override 039 @Nullable 040 protected CacheOperationSource getCacheOperationSource() { 041 return cacheOperationSource; 042 } 043 }; 044 045 046 /** 047 * Set the cache operation attribute source which is used to find cache 048 * attributes. This should usually be identical to the source reference 049 * set on the cache interceptor itself. 050 */ 051 public void setCacheOperationSource(CacheOperationSource cacheOperationSource) { 052 this.cacheOperationSource = cacheOperationSource; 053 } 054 055 /** 056 * Set the {@link ClassFilter} to use for this pointcut. 057 * Default is {@link ClassFilter#TRUE}. 058 */ 059 public void setClassFilter(ClassFilter classFilter) { 060 this.pointcut.setClassFilter(classFilter); 061 } 062 063 @Override 064 public Pointcut getPointcut() { 065 return this.pointcut; 066 } 067 068}