@@ -557,16 +557,16 @@ private Object generateKey(CacheOperationContext context, @Nullable Object resul
557
557
558
558
private class CacheOperationContexts {
559
559
560
- private final MultiValueMap <Class <? extends CacheOperation >, CacheOperationContext > contexts =
561
- new LinkedMultiValueMap <>();
560
+ private final MultiValueMap <Class <? extends CacheOperation >, CacheOperationContext > contexts ;
562
561
563
562
private final boolean sync ;
564
563
565
564
public CacheOperationContexts (Collection <? extends CacheOperation > operations , Method method ,
566
565
Object [] args , Object target , Class <?> targetClass ) {
567
566
568
- for (CacheOperation operation : operations ) {
569
- this .contexts .add (operation .getClass (), getOperationContext (operation , method , args , target , targetClass ));
567
+ this .contexts = new LinkedMultiValueMap <>(operations .size ());
568
+ for (CacheOperation op : operations ) {
569
+ this .contexts .add (op .getClass (), getOperationContext (op , method , args , target , targetClass ));
570
570
}
571
571
this .sync = determineSyncFlag (method );
572
572
}
@@ -594,18 +594,22 @@ private boolean determineSyncFlag(Method method) {
594
594
}
595
595
if (syncEnabled ) {
596
596
if (this .contexts .size () > 1 ) {
597
- throw new IllegalStateException ("@Cacheable(sync=true) cannot be combined with other cache operations on '" + method + "'" );
597
+ throw new IllegalStateException (
598
+ "@Cacheable(sync=true) cannot be combined with other cache operations on '" + method + "'" );
598
599
}
599
600
if (cacheOperationContexts .size () > 1 ) {
600
- throw new IllegalStateException ("Only one @Cacheable(sync=true) entry is allowed on '" + method + "'" );
601
+ throw new IllegalStateException (
602
+ "Only one @Cacheable(sync=true) entry is allowed on '" + method + "'" );
601
603
}
602
604
CacheOperationContext cacheOperationContext = cacheOperationContexts .iterator ().next ();
603
605
CacheableOperation operation = (CacheableOperation ) cacheOperationContext .getOperation ();
604
606
if (cacheOperationContext .getCaches ().size () > 1 ) {
605
- throw new IllegalStateException ("@Cacheable(sync=true) only allows a single cache on '" + operation + "'" );
607
+ throw new IllegalStateException (
608
+ "@Cacheable(sync=true) only allows a single cache on '" + operation + "'" );
606
609
}
607
610
if (StringUtils .hasText (operation .getUnless ())) {
608
- throw new IllegalStateException ("@Cacheable(sync=true) does not support unless attribute on '" + operation + "'" );
611
+ throw new IllegalStateException (
612
+ "@Cacheable(sync=true) does not support unless attribute on '" + operation + "'" );
609
613
}
610
614
return true ;
611
615
}
0 commit comments