Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
bfba53f9
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,体验更适合开发者的 AI 搜索 >>
提交
bfba53f9
编写于
12月 19, 2013
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed handling of primitive vararg array in CacheOperationContext
Issue: SPR-11249
上级
cb682cd8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
53 addition
and
15 deletion
+53
-15
spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
...springframework/cache/interceptor/CacheAspectSupport.java
+13
-10
spring-context/src/test/java/org/springframework/cache/CacheReproTests.java
.../test/java/org/springframework/cache/CacheReproTests.java
+40
-5
未找到文件。
spring-context/src/main/java/org/springframework/cache/interceptor/CacheAspectSupport.java
浏览文件 @
bfba53f9
...
...
@@ -25,6 +25,7 @@ import java.util.Set;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.springframework.aop.framework.AopProxyUtils
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.cache.Cache
;
...
...
@@ -37,6 +38,7 @@ import org.springframework.util.ClassUtils;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.LinkedMultiValueMap
;
import
org.springframework.util.MultiValueMap
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
/**
...
...
@@ -114,7 +116,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
/**
* Set the KeyGenerator for this cache aspect.
*
Default is {@link Default
KeyGenerator}.
*
The default is a {@link Simple
KeyGenerator}.
*/
public
void
setKeyGenerator
(
KeyGenerator
keyGenerator
)
{
this
.
keyGenerator
=
keyGenerator
;
...
...
@@ -249,8 +251,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
}
private
void
logInvalidating
(
CacheOperationContext
context
,
CacheEvictOperation
operation
,
Object
key
)
{
if
(
this
.
logger
.
isTraceEnabled
())
{
this
.
logger
.
trace
(
"Invalidating "
+
(
key
==
null
?
"entire cache"
:
"cache key "
+
key
)
+
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"Invalidating "
+
(
key
!=
null
?
"cache key ["
+
key
+
"]"
:
"entire cache"
)
+
" for operation "
+
operation
+
" on method "
+
context
.
method
);
}
}
...
...
@@ -302,8 +304,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
private
boolean
isConditionPassing
(
CacheOperationContext
context
,
Object
result
)
{
boolean
passing
=
context
.
isConditionPassing
(
result
);
if
(!
passing
&&
this
.
logger
.
isTraceEnabled
())
{
this
.
logger
.
trace
(
"Cache condition failed on method "
+
context
.
method
+
" for operation "
+
context
.
operation
);
if
(!
passing
&&
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"Cache condition failed on method "
+
context
.
method
+
" for operation "
+
context
.
operation
);
}
return
passing
;
}
...
...
@@ -312,8 +314,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
Object
key
=
context
.
generateKey
(
result
);
Assert
.
notNull
(
key
,
"Null key returned for cache operation (maybe you are using named params "
+
"on classes without debug info?) "
+
context
.
operation
);
if
(
this
.
logger
.
isTraceEnabled
())
{
this
.
logger
.
trace
(
"Computed cache key "
+
key
+
" for operation "
+
context
.
operation
);
if
(
logger
.
isTraceEnabled
())
{
logger
.
trace
(
"Computed cache key "
+
key
+
" for operation "
+
context
.
operation
);
}
return
key
;
}
...
...
@@ -334,7 +336,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
Method
method
,
Object
[]
args
,
Object
target
,
Class
<?>
targetClass
)
{
for
(
CacheOperation
operation
:
operations
)
{
this
.
contexts
.
add
(
operation
.
getClass
(),
new
Cache
OperationContext
(
operation
,
method
,
args
,
target
,
targetClass
));
this
.
contexts
.
add
(
operation
.
getClass
(),
get
OperationContext
(
operation
,
method
,
args
,
target
,
targetClass
));
}
}
...
...
@@ -373,7 +375,7 @@ public abstract class CacheAspectSupport implements InitializingBean {
if
(!
method
.
isVarArgs
())
{
return
args
;
}
Object
[]
varArgs
=
(
Object
[])
args
[
args
.
length
-
1
]
;
Object
[]
varArgs
=
ObjectUtils
.
toObjectArray
(
args
[
args
.
length
-
1
])
;
Object
[]
combinedArgs
=
new
Object
[
args
.
length
-
1
+
varArgs
.
length
];
System
.
arraycopy
(
args
,
0
,
combinedArgs
,
0
,
args
.
length
-
1
);
System
.
arraycopy
(
varArgs
,
0
,
combinedArgs
,
args
.
length
-
1
,
varArgs
.
length
);
...
...
@@ -416,7 +418,8 @@ public abstract class CacheAspectSupport implements InitializingBean {
}
private
EvaluationContext
createEvaluationContext
(
Object
result
)
{
return
evaluator
.
createEvaluationContext
(
this
.
caches
,
this
.
method
,
this
.
args
,
this
.
target
,
this
.
targetClass
,
result
);
return
evaluator
.
createEvaluationContext
(
this
.
caches
,
this
.
method
,
this
.
args
,
this
.
target
,
this
.
targetClass
,
result
);
}
protected
Collection
<?
extends
Cache
>
getCaches
()
{
...
...
spring-context/src/test/java/org/springframework/cache/CacheReproTests.java
浏览文件 @
bfba53f9
...
...
@@ -20,6 +20,7 @@ import java.util.Collections;
import
java.util.List
;
import
org.junit.Test
;
import
org.springframework.cache.annotation.Cacheable
;
import
org.springframework.cache.annotation.Caching
;
import
org.springframework.cache.annotation.EnableCaching
;
...
...
@@ -34,13 +35,13 @@ import static org.junit.Assert.*;
* Tests to reproduce raised caching issues.
*
* @author Phillip Webb
* @author Juergen Hoeller
*/
public
class
CacheReproTests
{
@Test
public
void
spr11124
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
Spr11124Config
.
class
);
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
Spr11124Config
.
class
);
Spr11124Service
bean
=
context
.
getBean
(
Spr11124Service
.
class
);
bean
.
single
(
2
);
bean
.
single
(
2
);
...
...
@@ -49,6 +50,16 @@ public class CacheReproTests {
context
.
close
();
}
@Test
public
void
spr11249
()
throws
Exception
{
AnnotationConfigApplicationContext
context
=
new
AnnotationConfigApplicationContext
(
Spr11249Config
.
class
);
Spr11249Service
bean
=
context
.
getBean
(
Spr11249Service
.
class
);
Object
result
=
bean
.
doSomething
(
"op"
,
2
,
3
);
assertSame
(
result
,
bean
.
doSomething
(
"op"
,
2
,
3
));
context
.
close
();
}
@Configuration
@EnableCaching
public
static
class
Spr11124Config
{
...
...
@@ -62,23 +73,23 @@ public class CacheReproTests {
public
Spr11124Service
service
()
{
return
new
Spr11124ServiceImpl
();
}
}
public
interface
Spr11124Service
{
public
List
<
String
>
single
(
int
id
);
public
List
<
String
>
multiple
(
int
id
);
}
public
static
class
Spr11124ServiceImpl
implements
Spr11124Service
{
private
int
multipleCount
=
0
;
@Override
@Cacheable
(
value
=
"smallCache"
)
@Cacheable
(
"smallCache"
)
public
List
<
String
>
single
(
int
id
)
{
if
(
this
.
multipleCount
>
0
)
{
fail
(
"Called too many times"
);
...
...
@@ -98,7 +109,31 @@ public class CacheReproTests {
this
.
multipleCount
++;
return
Collections
.
emptyList
();
}
}
@Configuration
@EnableCaching
public
static
class
Spr11249Config
{
@Bean
public
CacheManager
cacheManager
()
{
return
new
ConcurrentMapCacheManager
();
}
@Bean
public
Spr11249Service
service
()
{
return
new
Spr11249Service
();
}
}
public
static
class
Spr11249Service
{
@Cacheable
(
"smallCache"
)
public
Object
doSomething
(
String
name
,
int
...
values
)
{
return
new
Object
();
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录