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 java.util.ArrayList; 020import java.util.Arrays; 021import java.util.Collection; 022 023import org.springframework.cache.CacheManager; 024import org.springframework.lang.Nullable; 025 026/** 027 * A {@link CacheResolver} that forces the resolution to a configurable 028 * collection of name(s) against a given {@link CacheManager}. 029 * 030 * @author Stephane Nicoll 031 * @since 4.1 032 */ 033public class NamedCacheResolver extends AbstractCacheResolver { 034 035 @Nullable 036 private Collection<String> cacheNames; 037 038 039 public NamedCacheResolver() { 040 } 041 042 public NamedCacheResolver(CacheManager cacheManager, String... cacheNames) { 043 super(cacheManager); 044 this.cacheNames = new ArrayList<>(Arrays.asList(cacheNames)); 045 } 046 047 048 /** 049 * Set the cache name(s) that this resolver should use. 050 */ 051 public void setCacheNames(Collection<String> cacheNames) { 052 this.cacheNames = cacheNames; 053 } 054 055 @Override 056 protected Collection<String> getCacheNames(CacheOperationInvocationContext<?> context) { 057 return this.cacheNames; 058 } 059 060}