CacheProxyFactoryBean exposes all relevant CacheInterceptor callbacks
Issue: SPR-16295
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -51,22 +51,20 @@ import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Base class for caching aspects, such as the {@link CacheInterceptor}
|
||||
* or an AspectJ aspect.
|
||||
* Base class for caching aspects, such as the {@link CacheInterceptor} or an
|
||||
* AspectJ aspect.
|
||||
*
|
||||
* <p>This enables the underlying Spring caching infrastructure to be
|
||||
* used easily to implement an aspect for any aspect system.
|
||||
* <p>This enables the underlying Spring caching infrastructure to be used easily
|
||||
* to implement an aspect for any aspect system.
|
||||
*
|
||||
* <p>Subclasses are responsible for calling methods in this class in
|
||||
* the correct order.
|
||||
* <p>Subclasses are responsible for calling relevant methods in the correct order.
|
||||
*
|
||||
* <p>Uses the <b>Strategy</b> design pattern. A {@link CacheResolver}
|
||||
* implementation will resolve the actual cache(s) to use, and a
|
||||
* {@link CacheOperationSource} is used for determining caching
|
||||
* operations.
|
||||
* <p>Uses the <b>Strategy</b> design pattern. A {@link CacheOperationSource} is
|
||||
* used for determining caching operations, a {@link KeyGenerator} will build the
|
||||
* cache keys, and a {@link CacheResolver} will resolve the actual cache(s) to use.
|
||||
*
|
||||
* <p>A cache aspect is serializable if its {@code CacheResolver} and
|
||||
* {@code CacheOperationSource} are serializable.
|
||||
* <p>Note: A cache aspect is serializable but does not perform any actual caching
|
||||
* after deserialization.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author Juergen Hoeller
|
||||
@@ -121,7 +119,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
/**
|
||||
* Set the default {@link KeyGenerator} that this cache aspect should delegate to
|
||||
* if no specific key generator has been set for the operation.
|
||||
* <p>The default is a {@link SimpleKeyGenerator}
|
||||
* <p>The default is a {@link SimpleKeyGenerator}.
|
||||
*/
|
||||
public void setKeyGenerator(KeyGenerator keyGenerator) {
|
||||
this.keyGenerator = keyGenerator;
|
||||
@@ -134,22 +132,12 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
return this.keyGenerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link CacheManager} to use to create a default {@link CacheResolver}.
|
||||
* Replace the current {@link CacheResolver}, if any.
|
||||
* @see #setCacheResolver(CacheResolver)
|
||||
* @see SimpleCacheResolver
|
||||
*/
|
||||
public void setCacheManager(CacheManager cacheManager) {
|
||||
this.cacheResolver = new SimpleCacheResolver(cacheManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default {@link CacheResolver} that this cache aspect should delegate
|
||||
* to if no specific cache resolver has been set for the operation.
|
||||
* <p>The default resolver resolves the caches against their names and the
|
||||
* default cache manager.
|
||||
* @see #setCacheManager(org.springframework.cache.CacheManager)
|
||||
* @see #setCacheManager
|
||||
* @see SimpleCacheResolver
|
||||
*/
|
||||
public void setCacheResolver(@Nullable CacheResolver cacheResolver) {
|
||||
@@ -164,6 +152,16 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
||||
return this.cacheResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link CacheManager} to use to create a default {@link CacheResolver}.
|
||||
* Replace the current {@link CacheResolver}, if any.
|
||||
* @see #setCacheResolver
|
||||
* @see SimpleCacheResolver
|
||||
*/
|
||||
public void setCacheManager(CacheManager cacheManager) {
|
||||
this.cacheResolver = new SimpleCacheResolver(cacheManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the containing {@link BeanFactory} for {@link CacheManager} and other
|
||||
* service lookups.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,10 @@ package org.springframework.cache.interceptor;
|
||||
import org.springframework.aop.Pointcut;
|
||||
import org.springframework.aop.framework.AbstractSingletonProxyFactoryBean;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.cache.CacheManager;
|
||||
|
||||
/**
|
||||
* Proxy factory bean for simplified declarative caching handling.
|
||||
@@ -41,18 +45,53 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
* @see CacheInterceptor
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean {
|
||||
public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean
|
||||
implements BeanFactoryAware, SmartInitializingSingleton {
|
||||
|
||||
private final CacheInterceptor cachingInterceptor = new CacheInterceptor();
|
||||
private final CacheInterceptor cacheInterceptor = new CacheInterceptor();
|
||||
|
||||
private Pointcut pointcut = Pointcut.TRUE;
|
||||
|
||||
|
||||
/**
|
||||
* Set the sources used to find cache operations.
|
||||
* @see CacheInterceptor#setCacheOperationSources
|
||||
*/
|
||||
public void setCacheOperationSources(CacheOperationSource... cacheOperationSources) {
|
||||
this.cachingInterceptor.setCacheOperationSources(cacheOperationSources);
|
||||
this.cacheInterceptor.setCacheOperationSources(cacheOperationSources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default {@link KeyGenerator} that this cache aspect should delegate to
|
||||
* if no specific key generator has been set for the operation.
|
||||
* <p>The default is a {@link SimpleKeyGenerator}.
|
||||
* @since 5.0.3
|
||||
* @see CacheInterceptor#setKeyGenerator
|
||||
*/
|
||||
public void setKeyGenerator(KeyGenerator keyGenerator) {
|
||||
this.cacheInterceptor.setKeyGenerator(keyGenerator);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default {@link CacheResolver} that this cache aspect should delegate
|
||||
* to if no specific cache resolver has been set for the operation.
|
||||
* <p>The default resolver resolves the caches against their names and the
|
||||
* default cache manager.
|
||||
* @since 5.0.3
|
||||
* @see CacheInterceptor#setCacheResolver
|
||||
*/
|
||||
public void setCacheResolver(CacheResolver cacheResolver) {
|
||||
this.cacheInterceptor.setCacheResolver(cacheResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link CacheManager} to use to create a default {@link CacheResolver}.
|
||||
* Replace the current {@link CacheResolver}, if any.
|
||||
* @since 5.0.3
|
||||
* @see CacheInterceptor#setCacheManager
|
||||
*/
|
||||
public void setCacheManager(CacheManager cacheManager) {
|
||||
this.cacheInterceptor.setCacheManager(cacheManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,11 +105,21 @@ public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean {
|
||||
this.pointcut = pointcut;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
this.cacheInterceptor.setBeanFactory(beanFactory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSingletonsInstantiated() {
|
||||
this.cacheInterceptor.afterSingletonsInstantiated();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object createMainInterceptor() {
|
||||
this.cachingInterceptor.afterPropertiesSet();
|
||||
return new DefaultPointcutAdvisor(this.pointcut, this.cachingInterceptor);
|
||||
this.cacheInterceptor.afterPropertiesSet();
|
||||
return new DefaultPointcutAdvisor(this.pointcut, this.cacheInterceptor);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user