Skip to content

Commit 56e273c

Browse files
Optimize repeated annotation stream processing in cache annotation parsing
Closes: #35598 Signed-off-by: Kamil Krzywański <[email protected]> Signed-off-by: Kamil Krzywanski <[email protected]>
1 parent 26c57ce commit 56e273c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
* @author Phillip Webb
4545
* @author Stephane Nicoll
4646
* @author Sam Brannen
47+
* @author Kamil Krzywański
4748
* @since 3.1
4849
*/
4950
@SuppressWarnings("serial")
@@ -93,14 +94,20 @@ public boolean isCandidateClass(Class<?> targetClass) {
9394
}
9495

9596
Collection<CacheOperation> ops = new ArrayList<>(1);
96-
annotations.stream().filter(Cacheable.class::isInstance).map(Cacheable.class::cast).forEach(
97-
cacheable -> ops.add(parseCacheableAnnotation(ae, cachingConfig, cacheable)));
98-
annotations.stream().filter(CacheEvict.class::isInstance).map(CacheEvict.class::cast).forEach(
99-
cacheEvict -> ops.add(parseEvictAnnotation(ae, cachingConfig, cacheEvict)));
100-
annotations.stream().filter(CachePut.class::isInstance).map(CachePut.class::cast).forEach(
101-
cachePut -> ops.add(parsePutAnnotation(ae, cachingConfig, cachePut)));
102-
annotations.stream().filter(Caching.class::isInstance).map(Caching.class::cast).forEach(
103-
caching -> parseCachingAnnotation(ae, cachingConfig, caching, ops));
97+
for (Annotation annotation : annotations) {
98+
if (annotation instanceof Cacheable cacheable) {
99+
ops.add(parseCacheableAnnotation(ae, cachingConfig, cacheable));
100+
}
101+
if (annotation instanceof CacheEvict cacheEvict) {
102+
ops.add(parseEvictAnnotation(ae, cachingConfig, cacheEvict));
103+
}
104+
if (annotation instanceof CachePut cachePut) {
105+
ops.add(parsePutAnnotation(ae, cachingConfig, cachePut));
106+
}
107+
if (annotation instanceof Caching caching) {
108+
parseCachingAnnotation(ae, cachingConfig, caching, ops);
109+
}
110+
}
104111
return ops;
105112
}
106113

0 commit comments

Comments
 (0)