@@ -214,7 +214,7 @@ public void afterPropertiesSet() {
214214 @ Override
215215 public void afterSingletonsInstantiated () {
216216 if (getCacheResolver () == null ) {
217- // Lazily initialize cache resolver via default cache manager...
217+ // Lazily initialize cache resolver via default cache manager
218218 Assert .state (this .beanFactory != null , "CacheResolver or BeanFactory must be set on cache aspect" );
219219 try {
220220 setCacheManager (this .beanFactory .getBean (CacheManager .class ));
@@ -307,22 +307,22 @@ else if (StringUtils.hasText(operation.getCacheManager())) {
307307 }
308308
309309 /**
310- * Return a bean with the specified name and type. Used to resolve services that
311- * are referenced by name in a {@link CacheOperation}.
312- * @param beanName the name of the bean, as defined by the operation
313- * @param expectedType type for the bean
314- * @return the bean matching that name
310+ * Retrieve a bean with the specified name and type.
311+ * Used to resolve services that are referenced by name in a {@link CacheOperation}.
312+ * @param name the name of the bean, as defined by the cache operation
313+ * @param serviceType the type expected by the operation's service reference
314+ * @return the bean matching the expected type, qualified by the given name
315315 * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException if such bean does not exist
316316 * @see CacheOperation#getKeyGenerator()
317317 * @see CacheOperation#getCacheManager()
318318 * @see CacheOperation#getCacheResolver()
319319 */
320- protected <T > T getBean (String beanName , Class <T > expectedType ) {
320+ protected <T > T getBean (String name , Class <T > serviceType ) {
321321 if (this .beanFactory == null ) {
322322 throw new IllegalStateException (
323- "BeanFactory must be set on cache aspect for " + expectedType .getSimpleName () + " retrieval" );
323+ "BeanFactory must be set on cache aspect for " + serviceType .getSimpleName () + " retrieval" );
324324 }
325- return BeanFactoryAnnotationUtils .qualifiedBeanOfType (this .beanFactory , expectedType , beanName );
325+ return BeanFactoryAnnotationUtils .qualifiedBeanOfType (this .beanFactory , serviceType , name );
326326 }
327327
328328 /**
@@ -388,12 +388,11 @@ private Object execute(final CacheOperationInvoker invoker, Method method, Cache
388388 }
389389 }
390390 else {
391- // No caching required, only call the underlying method
391+ // No caching required, just call the underlying method
392392 return invokeOperation (invoker );
393393 }
394394 }
395395
396-
397396 // Process any early evictions
398397 processCacheEvicts (contexts .get (CacheEvictOperation .class ), true ,
399398 CacheOperationExpressionEvaluator .NO_RESULT );
@@ -641,21 +640,21 @@ private boolean determineSyncFlag(Method method) {
641640 if (syncEnabled ) {
642641 if (this .contexts .size () > 1 ) {
643642 throw new IllegalStateException (
644- "@Cacheable( sync=true) cannot be combined with other cache operations on '" + method + "'" );
643+ "A sync=true operation cannot be combined with other cache operations on '" + method + "'" );
645644 }
646645 if (cacheOperationContexts .size () > 1 ) {
647646 throw new IllegalStateException (
648- "Only one @Cacheable( sync=true) entry is allowed on '" + method + "'" );
647+ "Only one sync=true operation is allowed on '" + method + "'" );
649648 }
650649 CacheOperationContext cacheOperationContext = cacheOperationContexts .iterator ().next ();
651- CacheableOperation operation = ( CacheableOperation ) cacheOperationContext .getOperation ();
650+ CacheOperation operation = cacheOperationContext .getOperation ();
652651 if (cacheOperationContext .getCaches ().size () > 1 ) {
653652 throw new IllegalStateException (
654- "@Cacheable( sync=true) only allows a single cache on '" + operation + "'" );
653+ "A sync=true operation is restricted to a single cache on '" + operation + "'" );
655654 }
656- if (StringUtils .hasText (operation .getUnless ())) {
655+ if (operation instanceof CacheableOperation cacheable && StringUtils .hasText (cacheable .getUnless ())) {
657656 throw new IllegalStateException (
658- "@Cacheable( sync=true) does not support unless attribute on '" + operation + "'" );
657+ "A sync=true operation does not support the unless attribute on '" + operation + "'" );
659658 }
660659 return true ;
661660 }
@@ -884,13 +883,13 @@ public int compareTo(CacheOperationCacheKey other) {
884883 }
885884 }
886885
886+
887887 /**
888888 * Internal holder class for recording that a cache method was invoked.
889889 */
890890 private static class InvocationAwareResult {
891891
892892 boolean invoked ;
893-
894893 }
895894
896895}
0 commit comments