001/* 002 * Copyright 2002-2019 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 java.lang.reflect.Method; 020import java.util.Collection; 021 022import org.springframework.lang.Nullable; 023 024/** 025 * Interface used by {@link CacheInterceptor}. Implementations know how to source 026 * cache operation attributes, whether from configuration, metadata attributes at 027 * source level, or elsewhere. 028 * 029 * @author Costin Leau 030 * @author Juergen Hoeller 031 * @since 3.1 032 */ 033public interface CacheOperationSource { 034 035 /** 036 * Determine whether the given class is a candidate for cache operations 037 * in the metadata format of this {@code CacheOperationSource}. 038 * <p>If this method returns {@code false}, the methods on the given class 039 * will not get traversed for {@link #getCacheOperations} introspection. 040 * Returning {@code false} is therefore an optimization for non-affected 041 * classes, whereas {@code true} simply means that the class needs to get 042 * fully introspected for each method on the given class individually. 043 * @param targetClass the class to introspect 044 * @return {@code false} if the class is known to have no cache operation 045 * metadata at class or method level; {@code true} otherwise. The default 046 * implementation returns {@code true}, leading to regular introspection. 047 * @since 5.2 048 */ 049 default boolean isCandidateClass(Class<?> targetClass) { 050 return true; 051 } 052 053 /** 054 * Return the collection of cache operations for this method, 055 * or {@code null} if the method contains no <em>cacheable</em> annotations. 056 * @param method the method to introspect 057 * @param targetClass the target class (may be {@code null}, in which case 058 * the declaring class of the method must be used) 059 * @return all cache operations for this method, or {@code null} if none found 060 */ 061 @Nullable 062 Collection<CacheOperation> getCacheOperations(Method method, @Nullable Class<?> targetClass); 063 064}