|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2021 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -214,7 +214,7 @@ public void afterPropertiesSet() {
|
214 | 214 | @Override
|
215 | 215 | public void afterSingletonsInstantiated() {
|
216 | 216 | if (getCacheResolver() == null) {
|
217 |
| - // Lazily initialize cache resolver via default cache manager... |
| 217 | + // Lazily initialize cache resolver via default cache manager |
218 | 218 | Assert.state(this.beanFactory != null, "CacheResolver or BeanFactory must be set on cache aspect");
|
219 | 219 | try {
|
220 | 220 | setCacheManager(this.beanFactory.getBean(CacheManager.class));
|
@@ -307,22 +307,22 @@ else if (StringUtils.hasText(operation.getCacheManager())) {
|
307 | 307 | }
|
308 | 308 |
|
309 | 309 | /**
|
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 |
315 | 315 | * @throws org.springframework.beans.factory.NoSuchBeanDefinitionException if such bean does not exist
|
316 | 316 | * @see CacheOperation#getKeyGenerator()
|
317 | 317 | * @see CacheOperation#getCacheManager()
|
318 | 318 | * @see CacheOperation#getCacheResolver()
|
319 | 319 | */
|
320 |
| - protected <T> T getBean(String beanName, Class<T> expectedType) { |
| 320 | + protected <T> T getBean(String name, Class<T> serviceType) { |
321 | 321 | if (this.beanFactory == null) {
|
322 | 322 | 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"); |
324 | 324 | }
|
325 |
| - return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.beanFactory, expectedType, beanName); |
| 325 | + return BeanFactoryAnnotationUtils.qualifiedBeanOfType(this.beanFactory, serviceType, name); |
326 | 326 | }
|
327 | 327 |
|
328 | 328 | /**
|
@@ -388,12 +388,11 @@ private Object execute(final CacheOperationInvoker invoker, Method method, Cache
|
388 | 388 | }
|
389 | 389 | }
|
390 | 390 | else {
|
391 |
| - // No caching required, only call the underlying method |
| 391 | + // No caching required, just call the underlying method |
392 | 392 | return invokeOperation(invoker);
|
393 | 393 | }
|
394 | 394 | }
|
395 | 395 |
|
396 |
| - |
397 | 396 | // Process any early evictions
|
398 | 397 | processCacheEvicts(contexts.get(CacheEvictOperation.class), true,
|
399 | 398 | CacheOperationExpressionEvaluator.NO_RESULT);
|
@@ -641,21 +640,22 @@ private boolean determineSyncFlag(Method method) {
|
641 | 640 | if (syncEnabled) {
|
642 | 641 | if (this.contexts.size() > 1) {
|
643 | 642 | 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 + "'"); |
645 | 644 | }
|
646 | 645 | if (cacheOperationContexts.size() > 1) {
|
647 | 646 | throw new IllegalStateException(
|
648 |
| - "Only one @Cacheable(sync=true) entry is allowed on '" + method + "'"); |
| 647 | + "Only one sync=true operation is allowed on '" + method + "'"); |
649 | 648 | }
|
650 | 649 | CacheOperationContext cacheOperationContext = cacheOperationContexts.iterator().next();
|
651 |
| - CacheableOperation operation = (CacheableOperation) cacheOperationContext.getOperation(); |
| 650 | + CacheOperation operation = cacheOperationContext.getOperation(); |
652 | 651 | if (cacheOperationContext.getCaches().size() > 1) {
|
653 | 652 | 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 + "'"); |
655 | 654 | }
|
656 |
| - if (StringUtils.hasText(operation.getUnless())) { |
| 655 | + if (operation instanceof CacheableOperation && |
| 656 | + StringUtils.hasText(((CacheableOperation) operation).getUnless())) { |
657 | 657 | throw new IllegalStateException(
|
658 |
| - "@Cacheable(sync=true) does not support unless attribute on '" + operation + "'"); |
| 658 | + "A sync=true operation does not support the unless attribute on '" + operation + "'"); |
659 | 659 | }
|
660 | 660 | return true;
|
661 | 661 | }
|
@@ -885,13 +885,13 @@ public int compareTo(CacheOperationCacheKey other) {
|
885 | 885 | }
|
886 | 886 | }
|
887 | 887 |
|
| 888 | + |
888 | 889 | /**
|
889 | 890 | * Internal holder class for recording that a cache method was invoked.
|
890 | 891 | */
|
891 | 892 | private static class InvocationAwareResult {
|
892 | 893 |
|
893 | 894 | boolean invoked;
|
894 |
| - |
895 | 895 | }
|
896 | 896 |
|
897 | 897 | }
|
0 commit comments