@@ -586,16 +586,16 @@ private Object generateKey(CacheOperationContext context, @Nullable Object resul
586
586
587
587
private class CacheOperationContexts {
588
588
589
- private final MultiValueMap <Class <? extends CacheOperation >, CacheOperationContext > contexts =
590
- new LinkedMultiValueMap <>();
589
+ private final MultiValueMap <Class <? extends CacheOperation >, CacheOperationContext > contexts ;
591
590
592
591
private final boolean sync ;
593
592
594
593
public CacheOperationContexts (Collection <? extends CacheOperation > operations , Method method ,
595
594
Object [] args , Object target , Class <?> targetClass ) {
596
595
597
- for (CacheOperation operation : operations ) {
598
- this .contexts .add (operation .getClass (), getOperationContext (operation , method , args , target , targetClass ));
596
+ this .contexts = new LinkedMultiValueMap <>(operations .size ());
597
+ for (CacheOperation op : operations ) {
598
+ this .contexts .add (op .getClass (), getOperationContext (op , method , args , target , targetClass ));
599
599
}
600
600
this .sync = determineSyncFlag (method );
601
601
}
@@ -623,18 +623,22 @@ private boolean determineSyncFlag(Method method) {
623
623
}
624
624
if (syncEnabled ) {
625
625
if (this .contexts .size () > 1 ) {
626
- throw new IllegalStateException ("@Cacheable(sync=true) cannot be combined with other cache operations on '" + method + "'" );
626
+ throw new IllegalStateException (
627
+ "@Cacheable(sync=true) cannot be combined with other cache operations on '" + method + "'" );
627
628
}
628
629
if (cacheOperationContexts .size () > 1 ) {
629
- throw new IllegalStateException ("Only one @Cacheable(sync=true) entry is allowed on '" + method + "'" );
630
+ throw new IllegalStateException (
631
+ "Only one @Cacheable(sync=true) entry is allowed on '" + method + "'" );
630
632
}
631
633
CacheOperationContext cacheOperationContext = cacheOperationContexts .iterator ().next ();
632
634
CacheableOperation operation = (CacheableOperation ) cacheOperationContext .getOperation ();
633
635
if (cacheOperationContext .getCaches ().size () > 1 ) {
634
- throw new IllegalStateException ("@Cacheable(sync=true) only allows a single cache on '" + operation + "'" );
636
+ throw new IllegalStateException (
637
+ "@Cacheable(sync=true) only allows a single cache on '" + operation + "'" );
635
638
}
636
639
if (StringUtils .hasText (operation .getUnless ())) {
637
- throw new IllegalStateException ("@Cacheable(sync=true) does not support unless attribute on '" + operation + "'" );
640
+ throw new IllegalStateException (
641
+ "@Cacheable(sync=true) does not support unless attribute on '" + operation + "'" );
638
642
}
639
643
return true ;
640
644
}
0 commit comments