From 8be77cc65030db27495731899eb6e4043eccf2a4 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 21 Aug 2023 15:42:50 +0200 Subject: [PATCH] Revise documentation for cache infrastructure setup Closes gh-28250 --- .../pages/integration/cache/annotations.adoc | 18 ++++++++++++++++-- .../cache/annotation/CachingConfigurer.java | 6 +++--- .../cache/annotation/EnableCaching.java | 9 +++------ 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/framework-docs/modules/ROOT/pages/integration/cache/annotations.adoc b/framework-docs/modules/ROOT/pages/integration/cache/annotations.adoc index 1e9b9135941..68358c48ef2 100644 --- a/framework-docs/modules/ROOT/pages/integration/cache/annotations.adoc +++ b/framework-docs/modules/ROOT/pages/integration/cache/annotations.adoc @@ -424,10 +424,13 @@ Placing this annotation on the class does not turn on any caching operation. An operation-level customization always overrides a customization set on `@CacheConfig`. Therefore, this gives three levels of customizations for each cache operation: -* Globally configured, available for `CacheManager`, `KeyGenerator`. +* Globally configured, e.g. through `CachingConfigurer`: see next section. * At the class level, using `@CacheConfig`. * At the operation level. +NOTE: Provider-specific settings are typically available on the `CacheManager` bean, +e.g. on `CaffeineCacheManager`. These are effectively also global. + [[cache-annotation-enable]] == Enabling Caching Annotations @@ -446,6 +449,13 @@ To enable caching annotations add the annotation `@EnableCaching` to one of your @Configuration @EnableCaching public class AppConfig { + + @Bean + CacheManager cacheManager() { + CaffeineCacheManager cacheManager = new CaffeineCacheManager(); + cacheManager.setCacheSpecification(...); + return cacheManager; + } } ---- @@ -460,7 +470,11 @@ Alternatively, for XML configuration you can use the `cache:annotation-driven` e http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/cache https://www.springframework.org/schema/cache/spring-cache.xsd"> - + + + + + ---- diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java index a0a7c8a83d3..fe26f7d56d9 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,8 @@ import org.springframework.lang.Nullable; /** * Interface to be implemented by @{@link org.springframework.context.annotation.Configuration - * Configuration} classes annotated with @{@link EnableCaching} that wish or need to - * specify explicitly how caches are resolved and how keys are generated for annotation-driven + * Configuration} classes annotated with @{@link EnableCaching} that wish or need to specify + * explicitly how caches are resolved and how keys are generated for annotation-driven * cache management. * *

See @{@link EnableCaching} for general examples and context; see diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java b/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java index 126d3e0b74a..06ea231402d 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -141,11 +141,8 @@ import org.springframework.core.Ordered; * must be provided explicitly. Return {@code null} or {@code new SimpleKeyGenerator()} * from this method if no customization is necessary. * - *

{@link CachingConfigurer} offers additional customization options: it is recommended - * to extend from {@link org.springframework.cache.annotation.CachingConfigurerSupport - * CachingConfigurerSupport} that provides a default implementation for all methods which - * can be useful if you do not need to customize everything. See {@link CachingConfigurer} - * Javadoc for further details. + *

{@link CachingConfigurer} offers additional customization options: + * see the {@link CachingConfigurer} javadoc for further details. * *

The {@link #mode} attribute controls how advice is applied: If the mode is * {@link AdviceMode#PROXY} (the default), then the other attributes control the behavior