Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sesemomo
spring-framework
提交
8aa0b077
S
spring-framework
项目概览
sesemomo
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
8aa0b077
编写于
7月 20, 2019
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Consistent early eviction tests in regular and transactional scenarios
See gh-23192
上级
be65bef9
变更
11
展开全部
显示空白变更内容
内联
并排
Showing
11 changed file
with
288 addition
and
241 deletion
+288
-241
spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJCacheAnnotationTests.java
...gframework/cache/aspectj/AspectJCacheAnnotationTests.java
+1
-1
spring-aspects/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java
...ramework/cache/config/AnnotatedClassCacheableService.java
+25
-27
spring-aspects/src/test/java/org/springframework/cache/config/CacheableService.java
...va/org/springframework/cache/config/CacheableService.java
+6
-9
spring-aspects/src/test/java/org/springframework/cache/config/DefaultCacheableService.java
...springframework/cache/config/DefaultCacheableService.java
+30
-33
spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java
...gframework/cache/jcache/JCacheEhCacheAnnotationTests.java
+29
-2
spring-context/src/test/java/org/springframework/cache/config/AbstractCacheAnnotationTests.java
...gframework/cache/config/AbstractCacheAnnotationTests.java
+174
-135
spring-context/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java
...ramework/cache/config/AnnotatedClassCacheableService.java
+9
-12
spring-context/src/test/java/org/springframework/cache/config/CacheAdviceNamespaceTests.java
...ringframework/cache/config/CacheAdviceNamespaceTests.java
+1
-1
spring-context/src/test/java/org/springframework/cache/config/CacheableService.java
...va/org/springframework/cache/config/CacheableService.java
+5
-7
spring-context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java
...springframework/cache/config/DefaultCacheableService.java
+7
-12
spring-context/src/test/resources/org/springframework/cache/config/cache-advice.xml
...sources/org/springframework/cache/config/cache-advice.xml
+1
-2
未找到文件。
spring-aspects/src/test/java/org/springframework/cache/aspectj/AspectJCacheAnnotationTests.java
浏览文件 @
8aa0b077
...
@@ -38,7 +38,7 @@ public class AspectJCacheAnnotationTests extends AbstractCacheAnnotationTests {
...
@@ -38,7 +38,7 @@ public class AspectJCacheAnnotationTests extends AbstractCacheAnnotationTests {
}
}
@Test
@Test
public
void
testKeyStrategy
()
throws
Exception
{
public
void
testKeyStrategy
()
{
AnnotationCacheAspect
aspect
=
ctx
.
getBean
(
AnnotationCacheAspect
aspect
=
ctx
.
getBean
(
"org.springframework.cache.config.internalCacheAspect"
,
AnnotationCacheAspect
.
class
);
"org.springframework.cache.config.internalCacheAspect"
,
AnnotationCacheAspect
.
class
);
assertThat
(
aspect
.
getKeyGenerator
()).
isSameAs
(
ctx
.
getBean
(
"keyGenerator"
));
assertThat
(
aspect
.
getKeyGenerator
()).
isSameAs
(
ctx
.
getBean
(
"keyGenerator"
));
...
...
spring-aspects/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java
浏览文件 @
8aa0b077
/*
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -33,11 +33,13 @@ import org.springframework.cache.annotation.Caching;
...
@@ -33,11 +33,13 @@ import org.springframework.cache.annotation.Caching;
public
class
AnnotatedClassCacheableService
implements
CacheableService
<
Object
>
{
public
class
AnnotatedClassCacheableService
implements
CacheableService
<
Object
>
{
private
final
AtomicLong
counter
=
new
AtomicLong
();
private
final
AtomicLong
counter
=
new
AtomicLong
();
public
static
final
AtomicLong
nullInvocations
=
new
AtomicLong
();
public
static
final
AtomicLong
nullInvocations
=
new
AtomicLong
();
@Override
@Override
public
Object
cache
(
Object
arg1
)
{
public
Object
cache
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
...
@@ -48,7 +50,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
...
@@ -48,7 +50,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
sync
=
true
)
@Cacheable
(
cacheNames
=
"testCache"
,
sync
=
true
)
public
Object
cacheSync
(
Object
arg1
)
{
public
Object
cacheSync
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
...
@@ -68,13 +70,14 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
...
@@ -68,13 +70,14 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
unless
=
"#result > 10"
)
public
Object
unless
(
int
arg
)
{
public
Object
unless
(
int
arg
)
{
return
arg
;
return
arg
;
}
}
@Override
@Override
@CacheEvict
(
"testCache
"
)
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0
"
)
public
void
invalidate
(
Object
arg1
)
{
public
void
evict
(
Object
arg1
,
Object
arg2
)
{
}
}
@Override
@Override
...
@@ -83,11 +86,6 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
...
@@ -83,11 +86,6 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
throw
new
RuntimeException
(
"exception thrown - evict should NOT occur"
);
throw
new
RuntimeException
(
"exception thrown - evict should NOT occur"
);
}
}
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
)
public
void
evictAll
(
Object
arg1
)
{
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
beforeInvocation
=
true
)
@CacheEvict
(
cacheNames
=
"testCache"
,
beforeInvocation
=
true
)
public
void
evictEarly
(
Object
arg1
)
{
public
void
evictEarly
(
Object
arg1
)
{
...
@@ -95,68 +93,68 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
...
@@ -95,68 +93,68 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
}
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0"
)
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
)
public
void
evict
(
Object
arg1
,
Object
arg2
)
{
public
void
evict
All
(
Object
arg1
)
{
}
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0"
,
beforeInvocation
=
true
)
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
,
beforeInvocation
=
true
)
public
void
invalidateEarly
(
Object
arg1
,
Object
arg2
)
{
public
void
evictAllEarly
(
Object
arg1
)
{
throw
new
RuntimeException
(
"exception thrown - evict should still occur"
);
throw
new
RuntimeException
(
"exception thrown - evict should still occur"
);
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#p0"
)
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#p0"
)
public
Object
key
(
Object
arg1
,
Object
arg2
)
{
public
Object
key
(
Object
arg1
,
Object
arg2
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
"testCache"
)
@Cacheable
(
"testCache"
)
public
Object
varArgsKey
(
Object
...
args
)
{
public
Object
varArgsKey
(
Object
...
args
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#root.methodName + #root.caches[0].name"
)
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#root.methodName + #root.caches[0].name"
)
public
Object
name
(
Object
arg1
)
{
public
Object
name
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#root.methodName + #root.method.name + #root.targetClass + #root.target"
)
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#root.methodName + #root.method.name + #root.targetClass + #root.target"
)
public
Object
rootVars
(
Object
arg1
)
{
public
Object
rootVars
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
keyGenerator
=
"customKyeGenerator"
)
@Cacheable
(
cacheNames
=
"testCache"
,
keyGenerator
=
"customKyeGenerator"
)
public
Object
customKeyGenerator
(
Object
arg1
)
{
public
Object
customKeyGenerator
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
keyGenerator
=
"unknownBeanName"
)
@Cacheable
(
cacheNames
=
"testCache"
,
keyGenerator
=
"unknownBeanName"
)
public
Object
unknownCustomKeyGenerator
(
Object
arg1
)
{
public
Object
unknownCustomKeyGenerator
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
cacheManager
=
"customCacheManager"
)
@Cacheable
(
cacheNames
=
"testCache"
,
cacheManager
=
"customCacheManager"
)
public
Object
customCacheManager
(
Object
arg1
)
{
public
Object
customCacheManager
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
cacheManager
=
"unknownBeanName"
)
@Cacheable
(
cacheNames
=
"testCache"
,
cacheManager
=
"unknownBeanName"
)
public
Object
unknownCustomCacheManager
(
Object
arg1
)
{
public
Object
unknownCustomCacheManager
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@CachePut
(
"testCache"
)
@CachePut
(
"testCache"
)
public
Object
update
(
Object
arg1
)
{
public
Object
update
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
...
@@ -203,25 +201,25 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
...
@@ -203,25 +201,25 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
@Override
@Override
@Caching
(
cacheable
=
{
@Cacheable
(
"primary"
),
@Cacheable
(
"secondary"
)
})
@Caching
(
cacheable
=
{
@Cacheable
(
"primary"
),
@Cacheable
(
"secondary"
)
})
public
Object
multiCache
(
Object
arg1
)
{
public
Object
multiCache
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Caching
(
evict
=
{
@CacheEvict
(
"primary"
),
@CacheEvict
(
cacheNames
=
"secondary"
,
key
=
"#a0"
),
@CacheEvict
(
cacheNames
=
"primary"
,
key
=
"#p0 + 'A'"
)
})
@Caching
(
evict
=
{
@CacheEvict
(
"primary"
),
@CacheEvict
(
cacheNames
=
"secondary"
,
key
=
"#a0"
),
@CacheEvict
(
cacheNames
=
"primary"
,
key
=
"#p0 + 'A'"
)
})
public
Object
multiEvict
(
Object
arg1
)
{
public
Object
multiEvict
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Caching
(
cacheable
=
{
@Cacheable
(
cacheNames
=
"primary"
,
key
=
"#root.methodName"
)
},
evict
=
{
@CacheEvict
(
"secondary"
)
})
@Caching
(
cacheable
=
{
@Cacheable
(
cacheNames
=
"primary"
,
key
=
"#root.methodName"
)
},
evict
=
{
@CacheEvict
(
"secondary"
)
})
public
Object
multiCacheAndEvict
(
Object
arg1
)
{
public
Object
multiCacheAndEvict
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Caching
(
cacheable
=
{
@Cacheable
(
cacheNames
=
"primary"
,
condition
=
"#a0 == 3"
)
},
evict
=
{
@CacheEvict
(
"secondary"
)
})
@Caching
(
cacheable
=
{
@Cacheable
(
cacheNames
=
"primary"
,
condition
=
"#a0 == 3"
)
},
evict
=
{
@CacheEvict
(
"secondary"
)
})
public
Object
multiConditionalCacheAndEvict
(
Object
arg1
)
{
public
Object
multiConditionalCacheAndEvict
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
...
...
spring-aspects/src/test/java/org/springframework/cache/config/CacheableService.java
浏览文件 @
8aa0b077
/*
/*
* Copyright 2002-201
5
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
package
org.springframework.cache.config
;
package
org.springframework.cache.config
;
/**
/**
* Basic service interface.
* Basic service interface
for caching tests
.
*
*
* @author Costin Leau
* @author Costin Leau
* @author Phillip Webb
* @author Phillip Webb
...
@@ -33,17 +33,15 @@ public interface CacheableService<T> {
...
@@ -33,17 +33,15 @@ public interface CacheableService<T> {
T
cacheSyncNull
(
Object
arg1
);
T
cacheSyncNull
(
Object
arg1
);
void
invalidate
(
Object
arg1
);
void
evict
(
Object
arg1
,
Object
arg2
);
void
evictWithException
(
Object
arg1
);
void
evictEarly
(
Object
arg1
);
void
evictEarly
(
Object
arg1
);
void
evictAll
(
Object
arg1
);
void
evictAll
(
Object
arg1
);
void
evictWithException
(
Object
arg1
);
void
evictAllEarly
(
Object
arg1
);
void
evict
(
Object
arg1
,
Object
arg2
);
void
invalidateEarly
(
Object
arg1
,
Object
arg2
);
T
conditional
(
int
field
);
T
conditional
(
int
field
);
...
@@ -83,7 +81,6 @@ public interface CacheableService<T> {
...
@@ -83,7 +81,6 @@ public interface CacheableService<T> {
T
throwUncheckedSync
(
Object
arg1
);
T
throwUncheckedSync
(
Object
arg1
);
// multi annotations
T
multiCache
(
Object
arg1
);
T
multiCache
(
Object
arg1
);
T
multiEvict
(
Object
arg1
);
T
multiEvict
(
Object
arg1
);
...
...
spring-aspects/src/test/java/org/springframework/cache/config/DefaultCacheableService.java
浏览文件 @
8aa0b077
/*
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -25,7 +25,7 @@ import org.springframework.cache.annotation.Cacheable;
...
@@ -25,7 +25,7 @@ import org.springframework.cache.annotation.Cacheable;
import
org.springframework.cache.annotation.Caching
;
import
org.springframework.cache.annotation.Caching
;
/**
/**
* Simple cacheable service
* Simple cacheable service
.
*
*
* @author Costin Leau
* @author Costin Leau
* @author Phillip Webb
* @author Phillip Webb
...
@@ -34,12 +34,14 @@ import org.springframework.cache.annotation.Caching;
...
@@ -34,12 +34,14 @@ import org.springframework.cache.annotation.Caching;
public
class
DefaultCacheableService
implements
CacheableService
<
Long
>
{
public
class
DefaultCacheableService
implements
CacheableService
<
Long
>
{
private
final
AtomicLong
counter
=
new
AtomicLong
();
private
final
AtomicLong
counter
=
new
AtomicLong
();
private
final
AtomicLong
nullInvocations
=
new
AtomicLong
();
private
final
AtomicLong
nullInvocations
=
new
AtomicLong
();
@Override
@Override
@Cacheable
(
"testCache"
)
@Cacheable
(
"testCache"
)
public
Long
cache
(
Object
arg1
)
{
public
Long
cache
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
...
@@ -51,7 +53,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
...
@@ -51,7 +53,7 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
sync
=
true
)
@Cacheable
(
cacheNames
=
"testCache"
,
sync
=
true
)
public
Long
cacheSync
(
Object
arg1
)
{
public
Long
cacheSync
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
...
@@ -61,8 +63,8 @@ public class DefaultCacheableService implements CacheableService<Long> {
...
@@ -61,8 +63,8 @@ public class DefaultCacheableService implements CacheableService<Long> {
}
}
@Override
@Override
@CacheEvict
(
"testCache
"
)
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0
"
)
public
void
invalidate
(
Object
arg1
)
{
public
void
evict
(
Object
arg1
,
Object
arg2
)
{
}
}
@Override
@Override
...
@@ -71,11 +73,6 @@ public class DefaultCacheableService implements CacheableService<Long> {
...
@@ -71,11 +73,6 @@ public class DefaultCacheableService implements CacheableService<Long> {
throw
new
RuntimeException
(
"exception thrown - evict should NOT occur"
);
throw
new
RuntimeException
(
"exception thrown - evict should NOT occur"
);
}
}
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
)
public
void
evictAll
(
Object
arg1
)
{
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
beforeInvocation
=
true
)
@CacheEvict
(
cacheNames
=
"testCache"
,
beforeInvocation
=
true
)
public
void
evictEarly
(
Object
arg1
)
{
public
void
evictEarly
(
Object
arg1
)
{
...
@@ -83,26 +80,26 @@ public class DefaultCacheableService implements CacheableService<Long> {
...
@@ -83,26 +80,26 @@ public class DefaultCacheableService implements CacheableService<Long> {
}
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0"
)
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
)
public
void
evict
(
Object
arg1
,
Object
arg2
)
{
public
void
evict
All
(
Object
arg1
)
{
}
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0"
,
beforeInvocation
=
true
)
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
,
beforeInvocation
=
true
)
public
void
invalidateEarly
(
Object
arg1
,
Object
arg2
)
{
public
void
evictAllEarly
(
Object
arg1
)
{
throw
new
RuntimeException
(
"exception thrown - evict should still occur"
);
throw
new
RuntimeException
(
"exception thrown - evict should still occur"
);
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
condition
=
"#p0 == 3"
)
@Cacheable
(
cacheNames
=
"testCache"
,
condition
=
"#p0 == 3"
)
public
Long
conditional
(
int
classField
)
{
public
Long
conditional
(
int
classField
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
sync
=
true
,
condition
=
"#p0 == 3"
)
@Cacheable
(
cacheNames
=
"testCache"
,
sync
=
true
,
condition
=
"#p0 == 3"
)
public
Long
conditionalSync
(
int
f
ield
)
{
public
Long
conditionalSync
(
int
classF
ield
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
...
@@ -114,55 +111,55 @@ public class DefaultCacheableService implements CacheableService<Long> {
...
@@ -114,55 +111,55 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#p0"
)
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#p0"
)
public
Long
key
(
Object
arg1
,
Object
arg2
)
{
public
Long
key
(
Object
arg1
,
Object
arg2
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
)
@Cacheable
(
cacheNames
=
"testCache"
)
public
Long
varArgsKey
(
Object
...
args
)
{
public
Long
varArgsKey
(
Object
...
args
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#root.methodName"
)
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#root.methodName"
)
public
Long
name
(
Object
arg1
)
{
public
Long
name
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#root.methodName + #root.method.name + #root.targetClass + #root.target"
)
@Cacheable
(
cacheNames
=
"testCache"
,
key
=
"#root.methodName + #root.method.name + #root.targetClass + #root.target"
)
public
Long
rootVars
(
Object
arg1
)
{
public
Long
rootVars
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
keyGenerator
=
"customKeyGenerator"
)
@Cacheable
(
cacheNames
=
"testCache"
,
keyGenerator
=
"customKeyGenerator"
)
public
Long
customKeyGenerator
(
Object
arg1
)
{
public
Long
customKeyGenerator
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
keyGenerator
=
"unknownBeanName"
)
@Cacheable
(
cacheNames
=
"testCache"
,
keyGenerator
=
"unknownBeanName"
)
public
Long
unknownCustomKeyGenerator
(
Object
arg1
)
{
public
Long
unknownCustomKeyGenerator
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
cacheManager
=
"customCacheManager"
)
@Cacheable
(
cacheNames
=
"testCache"
,
cacheManager
=
"customCacheManager"
)
public
Long
customCacheManager
(
Object
arg1
)
{
public
Long
customCacheManager
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Cacheable
(
cacheNames
=
"testCache"
,
cacheManager
=
"unknownBeanName"
)
@Cacheable
(
cacheNames
=
"testCache"
,
cacheManager
=
"unknownBeanName"
)
public
Long
unknownCustomCacheManager
(
Object
arg1
)
{
public
Long
unknownCustomCacheManager
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@CachePut
(
"testCache"
)
@CachePut
(
"testCache"
)
public
Long
update
(
Object
arg1
)
{
public
Long
update
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
...
@@ -174,13 +171,13 @@ public class DefaultCacheableService implements CacheableService<Long> {
...
@@ -174,13 +171,13 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Override
@Cacheable
(
"testCache"
)
@Cacheable
(
"testCache"
)
public
Long
nullValue
(
Object
arg1
)
{
public
Long
nullValue
(
Object
arg1
)
{
nullInvocations
.
incrementAndGet
();
this
.
nullInvocations
.
incrementAndGet
();
return
null
;
return
null
;
}
}
@Override
@Override
public
Number
nullInvocations
()
{
public
Number
nullInvocations
()
{
return
nullInvocations
.
get
();
return
this
.
nullInvocations
.
get
();
}
}
@Override
@Override
...
@@ -212,25 +209,25 @@ public class DefaultCacheableService implements CacheableService<Long> {
...
@@ -212,25 +209,25 @@ public class DefaultCacheableService implements CacheableService<Long> {
@Override
@Override
@Caching
(
cacheable
=
{
@Cacheable
(
"primary"
),
@Cacheable
(
"secondary"
)
})
@Caching
(
cacheable
=
{
@Cacheable
(
"primary"
),
@Cacheable
(
"secondary"
)
})
public
Long
multiCache
(
Object
arg1
)
{
public
Long
multiCache
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Caching
(
evict
=
{
@CacheEvict
(
"primary"
),
@CacheEvict
(
cacheNames
=
"secondary"
,
key
=
"#p0"
),
@CacheEvict
(
cacheNames
=
"primary"
,
key
=
"#p0 + 'A'"
)
})
@Caching
(
evict
=
{
@CacheEvict
(
"primary"
),
@CacheEvict
(
cacheNames
=
"secondary"
,
key
=
"#p0"
),
@CacheEvict
(
cacheNames
=
"primary"
,
key
=
"#p0 + 'A'"
)
})
public
Long
multiEvict
(
Object
arg1
)
{
public
Long
multiEvict
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Caching
(
cacheable
=
{
@Cacheable
(
cacheNames
=
"primary"
,
key
=
"#root.methodName"
)
},
evict
=
{
@CacheEvict
(
"secondary"
)
})
@Caching
(
cacheable
=
{
@Cacheable
(
cacheNames
=
"primary"
,
key
=
"#root.methodName"
)
},
evict
=
{
@CacheEvict
(
"secondary"
)
})
public
Long
multiCacheAndEvict
(
Object
arg1
)
{
public
Long
multiCacheAndEvict
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
@Caching
(
cacheable
=
{
@Cacheable
(
cacheNames
=
"primary"
,
condition
=
"#p0 == 3"
)
},
evict
=
{
@CacheEvict
(
"secondary"
)
})
@Caching
(
cacheable
=
{
@Cacheable
(
cacheNames
=
"primary"
,
condition
=
"#p0 == 3"
)
},
evict
=
{
@CacheEvict
(
"secondary"
)
})
public
Long
multiConditionalCacheAndEvict
(
Object
arg1
)
{
public
Long
multiConditionalCacheAndEvict
(
Object
arg1
)
{
return
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
}
}
@Override
@Override
...
...
spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java
浏览文件 @
8aa0b077
/*
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -39,12 +39,17 @@ import org.springframework.context.ConfigurableApplicationContext;
...
@@ -39,12 +39,17 @@ import org.springframework.context.ConfigurableApplicationContext;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.AnnotationConfigApplicationContext
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.tests.transaction.CallCountingTransactionManager
;
import
org.springframework.transaction.support.TransactionTemplate
;
/**
/**
* @author Stephane Nicoll
* @author Stephane Nicoll
* @author Juergen Hoeller
*/
*/
public
class
JCacheEhCacheAnnotationTests
extends
AbstractCacheAnnotationTests
{
public
class
JCacheEhCacheAnnotationTests
extends
AbstractCacheAnnotationTests
{
private
final
TransactionTemplate
txTemplate
=
new
TransactionTemplate
(
new
CallCountingTransactionManager
());
private
CacheManager
jCacheManager
;
private
CacheManager
jCacheManager
;
...
@@ -76,6 +81,26 @@ public class JCacheEhCacheAnnotationTests extends AbstractCacheAnnotationTests {
...
@@ -76,6 +81,26 @@ public class JCacheEhCacheAnnotationTests extends AbstractCacheAnnotationTests {
public
void
testCustomCacheManager
()
{
public
void
testCustomCacheManager
()
{
}
}
@Test
public
void
testEvictWithTransaction
()
{
txTemplate
.
execute
(()
->
testEvict
(
this
.
cs
,
false
));
}
@Test
public
void
testEvictEarlyWithTransaction
()
{
txTemplate
.
execute
(()
->
testEvictEarly
(
this
.
cs
));
}
@Test
public
void
testEvictAllWithTransaction
()
{
txTemplate
.
execute
(()
->
testEvictAll
(
this
.
cs
,
false
));
}
@Test
public
void
testEvictAllEarlyWithTransaction
()
{
txTemplate
.
execute
(()
->
testEvictAllEarly
(
this
.
cs
));
}
@Configuration
@Configuration
@EnableCaching
@EnableCaching
...
@@ -87,7 +112,9 @@ public class JCacheEhCacheAnnotationTests extends AbstractCacheAnnotationTests {
...
@@ -87,7 +112,9 @@ public class JCacheEhCacheAnnotationTests extends AbstractCacheAnnotationTests {
@Override
@Override
@Bean
@Bean
public
org
.
springframework
.
cache
.
CacheManager
cacheManager
()
{
public
org
.
springframework
.
cache
.
CacheManager
cacheManager
()
{
return
new
JCacheCacheManager
(
jCacheManager
());
JCacheCacheManager
cm
=
new
JCacheCacheManager
(
jCacheManager
());
cm
.
setTransactionAware
(
true
);
return
cm
;
}
}
@Bean
@Bean
...
...
spring-context/src/test/java/org/springframework/cache/config/AbstractCacheAnnotationTests.java
浏览文件 @
8aa0b077
此差异已折叠。
点击以展开。
spring-context/src/test/java/org/springframework/cache/config/AnnotatedClassCacheableService.java
浏览文件 @
8aa0b077
/*
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -36,6 +36,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
...
@@ -36,6 +36,7 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
public
static
final
AtomicLong
nullInvocations
=
new
AtomicLong
();
public
static
final
AtomicLong
nullInvocations
=
new
AtomicLong
();
@Override
@Override
public
Object
cache
(
Object
arg1
)
{
public
Object
cache
(
Object
arg1
)
{
return
this
.
counter
.
getAndIncrement
();
return
this
.
counter
.
getAndIncrement
();
...
@@ -75,8 +76,8 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
...
@@ -75,8 +76,8 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
}
}
@Override
@Override
@CacheEvict
(
"testCache
"
)
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0
"
)
public
void
invalidate
(
Object
arg1
)
{
public
void
evict
(
Object
arg1
,
Object
arg2
)
{
}
}
@Override
@Override
...
@@ -85,11 +86,6 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
...
@@ -85,11 +86,6 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
throw
new
RuntimeException
(
"exception thrown - evict should NOT occur"
);
throw
new
RuntimeException
(
"exception thrown - evict should NOT occur"
);
}
}
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
)
public
void
evictAll
(
Object
arg1
)
{
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
beforeInvocation
=
true
)
@CacheEvict
(
cacheNames
=
"testCache"
,
beforeInvocation
=
true
)
public
void
evictEarly
(
Object
arg1
)
{
public
void
evictEarly
(
Object
arg1
)
{
...
@@ -97,13 +93,13 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
...
@@ -97,13 +93,13 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
}
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0"
)
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
)
public
void
evict
(
Object
arg1
,
Object
arg2
)
{
public
void
evict
All
(
Object
arg1
)
{
}
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0"
,
beforeInvocation
=
true
)
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
,
beforeInvocation
=
true
)
public
void
invalidateEarly
(
Object
arg1
,
Object
arg2
)
{
public
void
evictAllEarly
(
Object
arg1
)
{
throw
new
RuntimeException
(
"exception thrown - evict should still occur"
);
throw
new
RuntimeException
(
"exception thrown - evict should still occur"
);
}
}
...
@@ -238,4 +234,5 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
...
@@ -238,4 +234,5 @@ public class AnnotatedClassCacheableService implements CacheableService<Object>
arg1
.
setId
(
Long
.
MIN_VALUE
);
arg1
.
setId
(
Long
.
MIN_VALUE
);
return
arg1
;
return
arg1
;
}
}
}
}
spring-context/src/test/java/org/springframework/cache/config/CacheAdviceNamespaceTests.java
浏览文件 @
8aa0b077
...
@@ -37,7 +37,7 @@ public class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests {
...
@@ -37,7 +37,7 @@ public class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests {
}
}
@Test
@Test
public
void
testKeyStrategy
()
throws
Exception
{
public
void
testKeyStrategy
()
{
CacheInterceptor
bean
=
this
.
ctx
.
getBean
(
"cacheAdviceClass"
,
CacheInterceptor
.
class
);
CacheInterceptor
bean
=
this
.
ctx
.
getBean
(
"cacheAdviceClass"
,
CacheInterceptor
.
class
);
assertThat
(
bean
.
getKeyGenerator
()).
isSameAs
(
this
.
ctx
.
getBean
(
"keyGenerator"
));
assertThat
(
bean
.
getKeyGenerator
()).
isSameAs
(
this
.
ctx
.
getBean
(
"keyGenerator"
));
}
}
...
...
spring-context/src/test/java/org/springframework/cache/config/CacheableService.java
浏览文件 @
8aa0b077
/*
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -33,17 +33,15 @@ public interface CacheableService<T> {
...
@@ -33,17 +33,15 @@ public interface CacheableService<T> {
T
cacheSyncNull
(
Object
arg1
);
T
cacheSyncNull
(
Object
arg1
);
void
invalidate
(
Object
arg1
);
void
evict
(
Object
arg1
,
Object
arg2
);
void
evictWithException
(
Object
arg1
);
void
evictEarly
(
Object
arg1
);
void
evictEarly
(
Object
arg1
);
void
evictAll
(
Object
arg1
);
void
evictAll
(
Object
arg1
);
void
evictWithException
(
Object
arg1
);
void
evictAllEarly
(
Object
arg1
);
void
evict
(
Object
arg1
,
Object
arg2
);
void
invalidateEarly
(
Object
arg1
,
Object
arg2
);
T
conditional
(
int
field
);
T
conditional
(
int
field
);
...
...
spring-context/src/test/java/org/springframework/cache/config/DefaultCacheableService.java
浏览文件 @
8aa0b077
/*
/*
* Copyright 2002-201
7
the original author or authors.
* Copyright 2002-201
9
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -63,8 +63,8 @@ public class DefaultCacheableService implements CacheableService<Long> {
...
@@ -63,8 +63,8 @@ public class DefaultCacheableService implements CacheableService<Long> {
}
}
@Override
@Override
@CacheEvict
(
"testCache
"
)
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0
"
)
public
void
invalidate
(
Object
arg1
)
{
public
void
evict
(
Object
arg1
,
Object
arg2
)
{
}
}
@Override
@Override
...
@@ -73,11 +73,6 @@ public class DefaultCacheableService implements CacheableService<Long> {
...
@@ -73,11 +73,6 @@ public class DefaultCacheableService implements CacheableService<Long> {
throw
new
RuntimeException
(
"exception thrown - evict should NOT occur"
);
throw
new
RuntimeException
(
"exception thrown - evict should NOT occur"
);
}
}
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
)
public
void
evictAll
(
Object
arg1
)
{
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
beforeInvocation
=
true
)
@CacheEvict
(
cacheNames
=
"testCache"
,
beforeInvocation
=
true
)
public
void
evictEarly
(
Object
arg1
)
{
public
void
evictEarly
(
Object
arg1
)
{
...
@@ -85,13 +80,13 @@ public class DefaultCacheableService implements CacheableService<Long> {
...
@@ -85,13 +80,13 @@ public class DefaultCacheableService implements CacheableService<Long> {
}
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0"
)
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
)
public
void
evict
(
Object
arg1
,
Object
arg2
)
{
public
void
evict
All
(
Object
arg1
)
{
}
}
@Override
@Override
@CacheEvict
(
cacheNames
=
"testCache"
,
key
=
"#p0"
,
beforeInvocation
=
true
)
@CacheEvict
(
cacheNames
=
"testCache"
,
allEntries
=
true
,
beforeInvocation
=
true
)
public
void
invalidateEarly
(
Object
arg1
,
Object
arg2
)
{
public
void
evictAllEarly
(
Object
arg1
)
{
throw
new
RuntimeException
(
"exception thrown - evict should still occur"
);
throw
new
RuntimeException
(
"exception thrown - evict should still occur"
);
}
}
...
...
spring-context/src/test/resources/org/springframework/cache/config/cache-advice.xml
浏览文件 @
8aa0b077
...
@@ -27,12 +27,11 @@
...
@@ -27,12 +27,11 @@
<cache:cacheable
method=
"nullValue"
cache=
"testCache"
/>
<cache:cacheable
method=
"nullValue"
cache=
"testCache"
/>
</cache:caching>
</cache:caching>
<cache:caching>
<cache:caching>
<cache:cache-evict
method=
"invalidate"
cache=
"testCache"
/>
<cache:cache-evict
method=
"evict"
key=
"#p0"
cache=
"testCache"
/>
<cache:cache-evict
method=
"evict"
key=
"#p0"
cache=
"testCache"
/>
<cache:cache-evict
method=
"evictWithException"
cache=
"testCache"
/>
<cache:cache-evict
method=
"evictWithException"
cache=
"testCache"
/>
<cache:cache-evict
method=
"evictEarly"
cache=
"testCache"
before-invocation=
"true"
/>
<cache:cache-evict
method=
"evictEarly"
cache=
"testCache"
before-invocation=
"true"
/>
<cache:cache-evict
method=
"invalidateEarly"
key=
"#p0"
cache=
"testCache"
before-invocation=
"true"
/>
<cache:cache-evict
method=
"evictAll"
cache=
"testCache"
all-entries=
"true"
/>
<cache:cache-evict
method=
"evictAll"
cache=
"testCache"
all-entries=
"true"
/>
<cache:cache-evict
method=
"evictAllEarly"
cache=
"testCache"
all-entries=
"true"
before-invocation=
"true"
/>
</cache:caching>
</cache:caching>
<cache:caching
cache=
"testCache"
>
<cache:caching
cache=
"testCache"
>
<cache:cache-put
method=
"update"
/>
<cache:cache-put
method=
"update"
/>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录