Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Meiracle
spring-framework
提交
2d646ca7
S
spring-framework
项目概览
Meiracle
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
2d646ca7
编写于
8月 06, 2013
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polishing
上级
12459193
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
31 deletion
+21
-31
spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
...springframework/cache/interceptor/CacheAspectSupport.java
+21
-31
未找到文件。
spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
浏览文件 @
2d646ca7
...
@@ -135,8 +135,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -135,8 +135,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
throw
new
IllegalStateException
(
"'cacheManager' is required"
);
throw
new
IllegalStateException
(
"'cacheManager' is required"
);
}
}
if
(
this
.
cacheOperationSource
==
null
)
{
if
(
this
.
cacheOperationSource
==
null
)
{
throw
new
IllegalStateException
(
"The 'cacheOperationSources' property is required: "
throw
new
IllegalStateException
(
"The 'cacheOperationSources' property is required: "
+
+
"If there are no cacheable methods, then don't use a cache aspect."
);
"If there are no cacheable methods, then don't use a cache aspect."
);
}
}
this
.
initialized
=
true
;
this
.
initialized
=
true
;
...
@@ -163,7 +163,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -163,7 +163,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
for
(
String
cacheName
:
cacheNames
)
{
for
(
String
cacheName
:
cacheNames
)
{
Cache
cache
=
this
.
cacheManager
.
getCache
(
cacheName
);
Cache
cache
=
this
.
cacheManager
.
getCache
(
cacheName
);
if
(
cache
==
null
)
{
if
(
cache
==
null
)
{
throw
new
IllegalArgumentException
(
"Cannot find cache named
["
+
cacheName
+
"]
for "
+
operation
);
throw
new
IllegalArgumentException
(
"Cannot find cache named
'"
+
cacheName
+
"'
for "
+
operation
);
}
}
caches
.
add
(
cache
);
caches
.
add
(
cache
);
}
}
...
@@ -188,7 +188,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -188,7 +188,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
if
(
targetClass
==
null
&&
target
!=
null
)
{
if
(
targetClass
==
null
&&
target
!=
null
)
{
targetClass
=
target
.
getClass
();
targetClass
=
target
.
getClass
();
}
}
final
Collection
<
CacheOperation
>
cacheOp
=
getCacheOperationSource
().
getCacheOperations
(
method
,
targetClass
);
Collection
<
CacheOperation
>
cacheOp
=
getCacheOperationSource
().
getCacheOperations
(
method
,
targetClass
);
// analyze caching information
// analyze caching information
if
(!
CollectionUtils
.
isEmpty
(
cacheOp
))
{
if
(!
CollectionUtils
.
isEmpty
(
cacheOp
))
{
...
@@ -237,7 +237,6 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -237,7 +237,6 @@ public abstract class CacheAspectSupport implements InitializingBean {
// for each cache
// for each cache
// lazy key initialization
// lazy key initialization
Object
key
=
null
;
Object
key
=
null
;
for
(
Cache
cache
:
context
.
getCaches
())
{
for
(
Cache
cache
:
context
.
getCaches
())
{
// cache-wide flush
// cache-wide flush
if
(
evictOp
.
isCacheWide
())
{
if
(
evictOp
.
isCacheWide
())
{
...
@@ -284,9 +283,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -284,9 +283,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
logger
.
trace
(
"Computed cache key "
+
key
+
" for operation "
+
context
.
operation
);
logger
.
trace
(
"Computed cache key "
+
key
+
" for operation "
+
context
.
operation
);
}
}
if
(
key
==
null
)
{
if
(
key
==
null
)
{
throw
new
IllegalArgumentException
(
throw
new
IllegalArgumentException
(
"Null key returned for cache operation (maybe you "
+
"Null key returned for cache operation (maybe you are using named params on classes without debug info?) "
"are using named params on classes without debug info?) "
+
context
.
operation
);
+
context
.
operation
);
}
}
// add op/key (in case an update is discovered later on)
// add op/key (in case an update is discovered later on)
cacheUpdates
.
put
(
context
,
key
);
cacheUpdates
.
put
(
context
,
key
);
...
@@ -313,7 +311,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -313,7 +311,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
}
}
}
}
// return a status only if at least on cacheable matched
// return a status only if at least on
e
cacheable matched
if
(
atLeastOnePassed
)
{
if
(
atLeastOnePassed
)
{
return
new
CacheStatus
(
cacheUpdates
,
updateRequired
,
retVal
);
return
new
CacheStatus
(
cacheUpdates
,
updateRequired
,
retVal
);
}
}
...
@@ -333,9 +331,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -333,9 +331,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
logger
.
trace
(
"Computed cache key "
+
key
+
" for operation "
+
context
.
operation
);
logger
.
trace
(
"Computed cache key "
+
key
+
" for operation "
+
context
.
operation
);
}
}
if
(
key
==
null
)
{
if
(
key
==
null
)
{
throw
new
IllegalArgumentException
(
throw
new
IllegalArgumentException
(
"Null key returned for cache operation (maybe you "
+
"Null key returned for cache operation (maybe you are using named params on classes without debug info?) "
"are using named params on classes without debug info?) "
+
context
.
operation
);
+
context
.
operation
);
}
}
// add op/key (in case an update is discovered later on)
// add op/key (in case an update is discovered later on)
cacheUpdates
.
put
(
context
,
key
);
cacheUpdates
.
put
(
context
,
key
);
...
@@ -353,7 +350,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -353,7 +350,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
private
void
update
(
Map
<
CacheOperationContext
,
Object
>
updates
,
Object
retVal
)
{
private
void
update
(
Map
<
CacheOperationContext
,
Object
>
updates
,
Object
retVal
)
{
for
(
Map
.
Entry
<
CacheOperationContext
,
Object
>
entry
:
updates
.
entrySet
())
{
for
(
Map
.
Entry
<
CacheOperationContext
,
Object
>
entry
:
updates
.
entrySet
())
{
CacheOperationContext
operationContext
=
entry
.
getKey
();
CacheOperationContext
operationContext
=
entry
.
getKey
();
if
(
operationContext
.
canPutToCache
(
retVal
))
{
if
(
operationContext
.
canPutToCache
(
retVal
))
{
for
(
Cache
cache
:
operationContext
.
getCaches
())
{
for
(
Cache
cache
:
operationContext
.
getCaches
())
{
cache
.
put
(
entry
.
getValue
(),
retVal
);
cache
.
put
(
entry
.
getValue
(),
retVal
);
}
}
...
@@ -361,36 +358,31 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -361,36 +358,31 @@ public abstract class CacheAspectSupport implements InitializingBean {
}
}
}
}
private
Map
<
String
,
Collection
<
CacheOperationContext
>>
createOperationContext
(
Collection
<
CacheOperation
>
cacheOp
,
private
Map
<
String
,
Collection
<
CacheOperationContext
>>
createOperationContext
(
Method
method
,
Object
[]
args
,
Object
target
,
Class
<?>
targetClass
)
{
Collection
<
CacheOperation
>
cacheOperations
,
Method
method
,
Object
[]
args
,
Object
target
,
Class
<?>
targetClass
)
{
Map
<
String
,
Collection
<
CacheOperationContext
>>
map
=
new
LinkedHashMap
<
String
,
Collection
<
CacheOperationContext
>>(
3
);
Map
<
String
,
Collection
<
CacheOperationContext
>>
result
=
new
LinkedHashMap
<
String
,
Collection
<
CacheOperationContext
>>(
3
);
Collection
<
CacheOperationContext
>
cacheables
=
new
ArrayList
<
CacheOperationContext
>();
Collection
<
CacheOperationContext
>
cacheables
=
new
ArrayList
<
CacheOperationContext
>();
Collection
<
CacheOperationContext
>
evicts
=
new
ArrayList
<
CacheOperationContext
>();
Collection
<
CacheOperationContext
>
evicts
=
new
ArrayList
<
CacheOperationContext
>();
Collection
<
CacheOperationContext
>
updates
=
new
ArrayList
<
CacheOperationContext
>();
Collection
<
CacheOperationContext
>
updates
=
new
ArrayList
<
CacheOperationContext
>();
for
(
CacheOperation
cacheOperation
:
cacheOp
)
{
for
(
CacheOperation
cacheOperation
:
cacheOp
erations
)
{
CacheOperationContext
opContext
=
getOperationContext
(
cacheOperation
,
method
,
args
,
target
,
targetClass
);
CacheOperationContext
opContext
=
getOperationContext
(
cacheOperation
,
method
,
args
,
target
,
targetClass
);
if
(
cacheOperation
instanceof
CacheableOperation
)
{
if
(
cacheOperation
instanceof
CacheableOperation
)
{
cacheables
.
add
(
opContext
);
cacheables
.
add
(
opContext
);
}
}
if
(
cacheOperation
instanceof
CacheEvictOperation
)
{
if
(
cacheOperation
instanceof
CacheEvictOperation
)
{
evicts
.
add
(
opContext
);
evicts
.
add
(
opContext
);
}
}
if
(
cacheOperation
instanceof
CachePutOperation
)
{
if
(
cacheOperation
instanceof
CachePutOperation
)
{
updates
.
add
(
opContext
);
updates
.
add
(
opContext
);
}
}
}
}
map
.
put
(
CACHEABLE
,
cacheables
);
result
.
put
(
CACHEABLE
,
cacheables
);
map
.
put
(
EVICT
,
evicts
);
result
.
put
(
EVICT
,
evicts
);
map
.
put
(
UPDATE
,
updates
);
result
.
put
(
UPDATE
,
updates
);
return
result
;
return
map
;
}
}
...
@@ -430,8 +422,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -430,8 +422,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
protected
boolean
isConditionPassing
(
Object
result
)
{
protected
boolean
isConditionPassing
(
Object
result
)
{
if
(
StringUtils
.
hasText
(
this
.
operation
.
getCondition
()))
{
if
(
StringUtils
.
hasText
(
this
.
operation
.
getCondition
()))
{
EvaluationContext
evaluationContext
=
createEvaluationContext
(
result
);
EvaluationContext
evaluationContext
=
createEvaluationContext
(
result
);
return
evaluator
.
condition
(
this
.
operation
.
getCondition
(),
this
.
method
,
return
evaluator
.
condition
(
this
.
operation
.
getCondition
(),
this
.
method
,
evaluationContext
);
evaluationContext
);
}
}
return
true
;
return
true
;
}
}
...
@@ -444,7 +435,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -444,7 +435,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
else
if
(
this
.
operation
instanceof
CachePutOperation
)
{
else
if
(
this
.
operation
instanceof
CachePutOperation
)
{
unless
=
((
CachePutOperation
)
this
.
operation
).
getUnless
();
unless
=
((
CachePutOperation
)
this
.
operation
).
getUnless
();
}
}
if
(
StringUtils
.
hasText
(
unless
))
{
if
(
StringUtils
.
hasText
(
unless
))
{
EvaluationContext
evaluationContext
=
createEvaluationContext
(
value
);
EvaluationContext
evaluationContext
=
createEvaluationContext
(
value
);
return
!
evaluator
.
unless
(
unless
,
this
.
method
,
evaluationContext
);
return
!
evaluator
.
unless
(
unless
,
this
.
method
,
evaluationContext
);
}
}
...
@@ -464,8 +455,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
...
@@ -464,8 +455,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
}
}
private
EvaluationContext
createEvaluationContext
(
Object
result
)
{
private
EvaluationContext
createEvaluationContext
(
Object
result
)
{
return
evaluator
.
createEvaluationContext
(
this
.
caches
,
this
.
method
,
this
.
args
,
return
evaluator
.
createEvaluationContext
(
this
.
caches
,
this
.
method
,
this
.
args
,
this
.
target
,
this
.
targetClass
,
result
);
this
.
target
,
this
.
targetClass
,
result
);
}
}
protected
Collection
<
Cache
>
getCaches
()
{
protected
Collection
<
Cache
>
getCaches
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录