Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
f75d4e13
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f75d4e13
编写于
6月 21, 2013
作者:
P
Phillip Webb
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish cache abstraction code
Polish cache abstraction code and refactor CacheAspectSupport.
上级
b122ca68
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
305 addition
and
346 deletion
+305
-346
spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java
...mework/cache/annotation/AbstractCachingConfiguration.java
+5
-0
spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java
...a/org/springframework/cache/config/CacheAdviceParser.java
+67
-57
spring-context/src/main/java/org/springframework/cache/config/CacheNamespaceHandler.java
...g/springframework/cache/config/CacheNamespaceHandler.java
+1
-0
spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
...springframework/cache/interceptor/CacheAspectSupport.java
+203
-274
spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvictOperation.java
...pringframework/cache/interceptor/CacheEvictOperation.java
+1
-0
spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java
...g/springframework/cache/interceptor/CacheInterceptor.java
+10
-8
spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperation.java
...org/springframework/cache/interceptor/CacheOperation.java
+4
-1
spring-context/src/main/java/org/springframework/cache/interceptor/CacheProxyFactoryBean.java
...ingframework/cache/interceptor/CacheProxyFactoryBean.java
+4
-3
spring-context/src/main/java/org/springframework/cache/interceptor/CompositeCacheOperationSource.java
...work/cache/interceptor/CompositeCacheOperationSource.java
+1
-0
spring-context/src/main/java/org/springframework/cache/interceptor/DefaultKeyGenerator.java
...pringframework/cache/interceptor/DefaultKeyGenerator.java
+2
-0
spring-context/src/main/java/org/springframework/cache/interceptor/ExpressionEvaluator.java
...pringframework/cache/interceptor/ExpressionEvaluator.java
+1
-0
spring-context/src/main/java/org/springframework/cache/interceptor/LazyParamAwareEvaluationContext.java
...rk/cache/interceptor/LazyParamAwareEvaluationContext.java
+3
-3
spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java
...work/cache/interceptor/NameMatchCacheOperationSource.java
+2
-0
spring-context/src/main/java/org/springframework/cache/support/SimpleCacheManager.java
...org/springframework/cache/support/SimpleCacheManager.java
+1
-0
未找到文件。
spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java
浏览文件 @
f75d4e13
...
...
@@ -42,14 +42,18 @@ import org.springframework.util.CollectionUtils;
public
abstract
class
AbstractCachingConfiguration
implements
ImportAware
{
protected
AnnotationAttributes
enableCaching
;
protected
CacheManager
cacheManager
;
protected
KeyGenerator
keyGenerator
;
@Autowired
(
required
=
false
)
private
Collection
<
CacheManager
>
cacheManagerBeans
;
@Autowired
(
required
=
false
)
private
Collection
<
CachingConfigurer
>
cachingConfigurers
;
@Override
public
void
setImportMetadata
(
AnnotationMetadata
importMetadata
)
{
this
.
enableCaching
=
AnnotationAttributes
.
fromMap
(
...
...
@@ -59,6 +63,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
importMetadata
.
getClassName
());
}
/**
* Determine which {@code CacheManager} bean to use. Prefer the result of
* {@link CachingConfigurer#cacheManager()} over any by-type matching. If none, fall
...
...
spring-context/src/main/java/org/springframework/cache/config/CacheAdviceParser.java
浏览文件 @
f75d4e13
...
...
@@ -48,69 +48,17 @@ import org.w3c.dom.Element;
*/
class
CacheAdviceParser
extends
AbstractSingleBeanDefinitionParser
{
/**
* Simple, reusable class used for overriding defaults.
*
* @author Costin Leau
*/
private
static
class
Props
{
private
String
key
;
private
String
condition
;
private
String
method
;
private
String
[]
caches
=
null
;
Props
(
Element
root
)
{
String
defaultCache
=
root
.
getAttribute
(
"cache"
);
key
=
root
.
getAttribute
(
"key"
);
condition
=
root
.
getAttribute
(
"condition"
);
method
=
root
.
getAttribute
(
METHOD_ATTRIBUTE
);
if
(
StringUtils
.
hasText
(
defaultCache
))
{
caches
=
StringUtils
.
commaDelimitedListToStringArray
(
defaultCache
.
trim
());
}
}
<
T
extends
CacheOperation
>
T
merge
(
Element
element
,
ReaderContext
readerCtx
,
T
op
)
{
String
cache
=
element
.
getAttribute
(
"cache"
);
// sanity check
String
[]
localCaches
=
caches
;
if
(
StringUtils
.
hasText
(
cache
))
{
localCaches
=
StringUtils
.
commaDelimitedListToStringArray
(
cache
.
trim
());
}
else
{
if
(
caches
==
null
)
{
readerCtx
.
error
(
"No cache specified specified for "
+
element
.
getNodeName
(),
element
);
}
}
op
.
setCacheNames
(
localCaches
);
op
.
setKey
(
getAttributeValue
(
element
,
"key"
,
this
.
key
));
op
.
setCondition
(
getAttributeValue
(
element
,
"condition"
,
this
.
condition
));
return
op
;
}
String
merge
(
Element
element
,
ReaderContext
readerCtx
)
{
String
m
=
element
.
getAttribute
(
METHOD_ATTRIBUTE
);
if
(
StringUtils
.
hasText
(
m
))
{
return
m
.
trim
();
}
if
(
StringUtils
.
hasText
(
method
))
{
return
method
;
}
readerCtx
.
error
(
"No method specified for "
+
element
.
getNodeName
(),
element
);
return
null
;
}
}
private
static
final
String
CACHEABLE_ELEMENT
=
"cacheable"
;
private
static
final
String
CACHE_EVICT_ELEMENT
=
"cache-evict"
;
private
static
final
String
CACHE_PUT_ELEMENT
=
"cache-put"
;
private
static
final
String
METHOD_ATTRIBUTE
=
"method"
;
private
static
final
String
DEFS_ELEMENT
=
"caching"
;
@Override
protected
Class
<?>
getBeanClass
(
Element
element
)
{
return
CacheInterceptor
.
class
;
...
...
@@ -226,4 +174,66 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser {
return
defaultValue
;
}
/**
* Simple, reusable class used for overriding defaults.
*
* @author Costin Leau
*/
private
static
class
Props
{
private
String
key
;
private
String
condition
;
private
String
method
;
private
String
[]
caches
=
null
;
Props
(
Element
root
)
{
String
defaultCache
=
root
.
getAttribute
(
"cache"
);
key
=
root
.
getAttribute
(
"key"
);
condition
=
root
.
getAttribute
(
"condition"
);
method
=
root
.
getAttribute
(
METHOD_ATTRIBUTE
);
if
(
StringUtils
.
hasText
(
defaultCache
))
{
caches
=
StringUtils
.
commaDelimitedListToStringArray
(
defaultCache
.
trim
());
}
}
<
T
extends
CacheOperation
>
T
merge
(
Element
element
,
ReaderContext
readerCtx
,
T
op
)
{
String
cache
=
element
.
getAttribute
(
"cache"
);
// sanity check
String
[]
localCaches
=
caches
;
if
(
StringUtils
.
hasText
(
cache
))
{
localCaches
=
StringUtils
.
commaDelimitedListToStringArray
(
cache
.
trim
());
}
else
{
if
(
caches
==
null
)
{
readerCtx
.
error
(
"No cache specified specified for "
+
element
.
getNodeName
(),
element
);
}
}
op
.
setCacheNames
(
localCaches
);
op
.
setKey
(
getAttributeValue
(
element
,
"key"
,
this
.
key
));
op
.
setCondition
(
getAttributeValue
(
element
,
"condition"
,
this
.
condition
));
return
op
;
}
String
merge
(
Element
element
,
ReaderContext
readerCtx
)
{
String
m
=
element
.
getAttribute
(
METHOD_ATTRIBUTE
);
if
(
StringUtils
.
hasText
(
m
))
{
return
m
.
trim
();
}
if
(
StringUtils
.
hasText
(
method
))
{
return
method
;
}
readerCtx
.
error
(
"No method specified for "
+
element
.
getNodeName
(),
element
);
return
null
;
}
}
}
spring-context/src/main/java/org/springframework/cache/config/CacheNamespaceHandler.java
浏览文件 @
f75d4e13
...
...
@@ -35,6 +35,7 @@ import org.w3c.dom.Element;
public
class
CacheNamespaceHandler
extends
NamespaceHandlerSupport
{
static
final
String
CACHE_MANAGER_ATTRIBUTE
=
"cache-manager"
;
static
final
String
DEFAULT_CACHE_MANAGER_BEAN_NAME
=
"cacheManager"
;
static
String
extractCacheManager
(
Element
element
)
{
...
...
spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
浏览文件 @
f75d4e13
此差异已折叠。
点击以展开。
spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvictOperation.java
浏览文件 @
f75d4e13
...
...
@@ -25,6 +25,7 @@ package org.springframework.cache.interceptor;
public
class
CacheEvictOperation
extends
CacheOperation
{
private
boolean
cacheWide
=
false
;
private
boolean
beforeInvocation
=
false
;
...
...
spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java
浏览文件 @
f75d4e13
...
...
@@ -41,14 +41,6 @@ import org.aopalliance.intercept.MethodInvocation;
@SuppressWarnings
(
"serial"
)
public
class
CacheInterceptor
extends
CacheAspectSupport
implements
MethodInterceptor
,
Serializable
{
private
static
class
ThrowableWrapper
extends
RuntimeException
{
private
final
Throwable
original
;
ThrowableWrapper
(
Throwable
original
)
{
this
.
original
=
original
;
}
}
@Override
public
Object
invoke
(
final
MethodInvocation
invocation
)
throws
Throwable
{
Method
method
=
invocation
.
getMethod
();
...
...
@@ -70,4 +62,14 @@ public class CacheInterceptor extends CacheAspectSupport implements MethodInterc
throw
th
.
original
;
}
}
private
static
class
ThrowableWrapper
extends
RuntimeException
{
private
final
Throwable
original
;
ThrowableWrapper
(
Throwable
original
)
{
this
.
original
=
original
;
}
}
}
spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperation.java
浏览文件 @
f75d4e13
...
...
@@ -23,15 +23,18 @@ import java.util.Set;
import
org.springframework.util.Assert
;
/**
* Base class
implementing {@link CacheOperation}
.
* Base class
for cache operations
.
*
* @author Costin Leau
*/
public
abstract
class
CacheOperation
{
private
Set
<
String
>
cacheNames
=
Collections
.
emptySet
();
private
String
condition
=
""
;
private
String
key
=
""
;
private
String
name
=
""
;
...
...
spring-context/src/main/java/org/springframework/cache/interceptor/CacheProxyFactoryBean.java
浏览文件 @
f75d4e13
...
...
@@ -42,8 +42,10 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
public
class
CacheProxyFactoryBean
extends
AbstractSingletonProxyFactoryBean
{
private
final
CacheInterceptor
cachingInterceptor
=
new
CacheInterceptor
();
private
Pointcut
pointcut
;
/**
* Set a pointcut, i.e a bean that can cause conditional invocation
* of the CacheInterceptor depending on method and attributes passed.
...
...
@@ -58,12 +60,11 @@ public class CacheProxyFactoryBean extends AbstractSingletonProxyFactoryBean {
@Override
protected
Object
createMainInterceptor
()
{
this
.
cachingInterceptor
.
afterPropertiesSet
();
if
(
this
.
pointcut
!=
null
)
{
return
new
DefaultPointcutAdvisor
(
this
.
pointcut
,
this
.
cachingInterceptor
);
}
else
{
if
(
this
.
pointcut
==
null
)
{
// Rely on default pointcut.
throw
new
UnsupportedOperationException
();
}
return
new
DefaultPointcutAdvisor
(
this
.
pointcut
,
this
.
cachingInterceptor
);
}
/**
...
...
spring-context/src/main/java/org/springframework/cache/interceptor/CompositeCacheOperationSource.java
浏览文件 @
f75d4e13
...
...
@@ -35,6 +35,7 @@ public class CompositeCacheOperationSource implements CacheOperationSource, Seri
private
final
CacheOperationSource
[]
cacheOperationSources
;
/**
* Create a new CompositeCacheOperationSource for the given sources.
* @param cacheOperationSources the CacheOperationSource instances to combine
...
...
spring-context/src/main/java/org/springframework/cache/interceptor/DefaultKeyGenerator.java
浏览文件 @
f75d4e13
...
...
@@ -42,8 +42,10 @@ import org.springframework.cache.interceptor.KeyGenerator;
public
class
DefaultKeyGenerator
implements
KeyGenerator
{
public
static
final
int
NO_PARAM_KEY
=
0
;
public
static
final
int
NULL_PARAM_KEY
=
53
;
@Override
public
Object
generate
(
Object
target
,
Method
method
,
Object
...
params
)
{
if
(
params
.
length
==
1
)
{
...
...
spring-context/src/main/java/org/springframework/cache/interceptor/ExpressionEvaluator.java
浏览文件 @
f75d4e13
...
...
@@ -42,6 +42,7 @@ class ExpressionEvaluator {
public
static
final
Object
NO_RESULT
=
new
Object
();
private
final
SpelExpressionParser
parser
=
new
SpelExpressionParser
();
// shared param discoverer since it caches data internally
...
...
spring-context/src/main/java/org/springframework/cache/interceptor/LazyParamAwareEvaluationContext.java
浏览文件 @
f75d4e13
...
...
@@ -85,14 +85,14 @@ class LazyParamAwareEvaluationContext extends StandardEvaluationContext {
return
;
}
String
mKey
=
toString
(
this
.
method
);
Method
targetMethod
=
this
.
methodCache
.
get
(
mKey
);
String
m
ethod
Key
=
toString
(
this
.
method
);
Method
targetMethod
=
this
.
methodCache
.
get
(
m
ethod
Key
);
if
(
targetMethod
==
null
)
{
targetMethod
=
AopUtils
.
getMostSpecificMethod
(
this
.
method
,
this
.
targetClass
);
if
(
targetMethod
==
null
)
{
targetMethod
=
this
.
method
;
}
this
.
methodCache
.
put
(
mKey
,
targetMethod
);
this
.
methodCache
.
put
(
m
ethod
Key
,
targetMethod
);
}
// save arguments as indexed variables
...
...
spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java
浏览文件 @
f75d4e13
...
...
@@ -42,9 +42,11 @@ public class NameMatchCacheOperationSource implements CacheOperationSource, Seri
*/
protected
static
final
Log
logger
=
LogFactory
.
getLog
(
NameMatchCacheOperationSource
.
class
);
/** Keys are method names; values are TransactionAttributes */
private
Map
<
String
,
Collection
<
CacheOperation
>>
nameMap
=
new
LinkedHashMap
<
String
,
Collection
<
CacheOperation
>>();
/**
* Set a name/attribute map, consisting of method names
* (e.g. "myMethod") and CacheOperation instances
...
...
spring-context/src/main/java/org/springframework/cache/support/SimpleCacheManager.java
浏览文件 @
f75d4e13
...
...
@@ -31,6 +31,7 @@ public class SimpleCacheManager extends AbstractCacheManager {
private
Collection
<?
extends
Cache
>
caches
;
/**
* Specify the collection of Cache instances to use for this CacheManager.
*/
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录