polishing
This commit is contained in:
@@ -33,16 +33,18 @@ import org.springframework.util.Assert;
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
*/
|
||||
public abstract class BaseCacheResolver implements CacheResolver, InitializingBean {
|
||||
public abstract class AbstractCacheResolver implements CacheResolver, InitializingBean {
|
||||
|
||||
private CacheManager cacheManager;
|
||||
|
||||
protected BaseCacheResolver(CacheManager cacheManager) {
|
||||
|
||||
protected AbstractCacheResolver() {
|
||||
}
|
||||
|
||||
protected AbstractCacheResolver(CacheManager cacheManager) {
|
||||
this.cacheManager = cacheManager;
|
||||
}
|
||||
|
||||
protected BaseCacheResolver() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link CacheManager} that this instance should use.
|
||||
@@ -55,14 +57,15 @@ public abstract class BaseCacheResolver implements CacheResolver, InitializingBe
|
||||
* Return the {@link CacheManager} that this instance use.
|
||||
*/
|
||||
public CacheManager getCacheManager() {
|
||||
return cacheManager;
|
||||
return this.cacheManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
Assert.notNull(cacheManager, "CacheManager must not be null");
|
||||
Assert.notNull(this.cacheManager, "CacheManager must not be null");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Collection<? extends Cache> resolveCaches(CacheOperationInvocationContext<?> context) {
|
||||
Collection<String> cacheNames = getCacheNames(context);
|
||||
@@ -72,8 +75,11 @@ public abstract class BaseCacheResolver implements CacheResolver, InitializingBe
|
||||
else {
|
||||
Collection<Cache> result = new ArrayList<Cache>();
|
||||
for (String cacheName : cacheNames) {
|
||||
Cache cache = cacheManager.getCache(cacheName);
|
||||
Assert.notNull(cache, "Cannot find cache named '" + cacheName + "' for " + context.getOperation());
|
||||
Cache cache = this.cacheManager.getCache(cacheName);
|
||||
if (cache == null) {
|
||||
throw new IllegalArgumentException("Cannot find cache named '" +
|
||||
cacheName + "' for " + context.getOperation());
|
||||
}
|
||||
result.add(cache);
|
||||
}
|
||||
return result;
|
||||
@@ -84,7 +90,6 @@ public abstract class BaseCacheResolver implements CacheResolver, InitializingBe
|
||||
* Provide the name of the cache(s) to resolve against the current cache manager.
|
||||
* <p>It is acceptable to return {@code null} to indicate that no cache could
|
||||
* be resolved for this invocation.
|
||||
*
|
||||
* @param context the context of the particular invocation
|
||||
* @return the cache name(s) to resolve or {@code null} if no cache should be resolved
|
||||
*/
|
||||
@@ -24,7 +24,7 @@ import java.util.Set;
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
*/
|
||||
public interface BasicCacheOperation {
|
||||
public interface BasicOperation {
|
||||
|
||||
/**
|
||||
* Return the cache name(s) associated to the operation.
|
||||
@@ -29,7 +29,7 @@ import org.springframework.util.Assert;
|
||||
* @author Stephane Nicoll
|
||||
* @since 3.1
|
||||
*/
|
||||
public abstract class CacheOperation implements BasicCacheOperation {
|
||||
public abstract class CacheOperation implements BasicOperation {
|
||||
|
||||
private Set<String> cacheNames = Collections.emptySet();
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.lang.reflect.Method;
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
*/
|
||||
public interface CacheOperationInvocationContext<O extends BasicCacheOperation> {
|
||||
public interface CacheOperationInvocationContext<O extends BasicOperation> {
|
||||
|
||||
/**
|
||||
* Return the cache operation
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.cache.CacheManager;
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
*/
|
||||
public class NamedCacheResolver extends BaseCacheResolver {
|
||||
public class NamedCacheResolver extends AbstractCacheResolver {
|
||||
|
||||
private Collection<String> cacheNames;
|
||||
|
||||
|
||||
@@ -24,13 +24,13 @@ import org.springframework.cache.CacheManager;
|
||||
/**
|
||||
* A simple {@link CacheResolver} that resolves the {@link Cache} instance(s)
|
||||
* based on a configurable {@link CacheManager} and the name of the
|
||||
* cache(s) as provided by {@link BasicCacheOperation#getCacheNames() getCacheNames()}
|
||||
* cache(s) as provided by {@link BasicOperation#getCacheNames() getCacheNames()}
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
* @see BasicCacheOperation#getCacheNames()
|
||||
* @see BasicOperation#getCacheNames()
|
||||
*/
|
||||
public class SimpleCacheResolver extends BaseCacheResolver {
|
||||
public class SimpleCacheResolver extends AbstractCacheResolver {
|
||||
|
||||
public SimpleCacheResolver() {
|
||||
}
|
||||
|
||||
@@ -39,6 +39,13 @@ public class SimpleKeyGenerator implements KeyGenerator {
|
||||
|
||||
@Override
|
||||
public Object generate(Object target, Method method, Object... params) {
|
||||
return generateKey(params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a key based on the specified parameters.
|
||||
*/
|
||||
public static Object generateKey(Object... params) {
|
||||
if (params.length == 0) {
|
||||
return SimpleKey.EMPTY;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user