Skip to content

Commit 652a5e7

Browse files
committed
Merge branch '1.4.x' into 1.5.x
2 parents 76ee2f4 + f060922 commit 652a5e7

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4022,24 +4022,28 @@ relevant annotation to its method:
40224022

40234023
[source,java,indent=0]
40244024
----
4025-
import javax.cache.annotation.CacheResult;
4026-
4025+
import org.springframework.cache.annotation.Cacheable
40274026
import org.springframework.stereotype.Component;
40284027
40294028
@Component
40304029
public class MathService {
40314030
4032-
@CacheResult
4031+
@Cacheable("piDecimals")
40334032
public int computePiDecimal(int i) {
40344033
// ...
40354034
}
40364035
40374036
}
40384037
----
40394038

4040-
NOTE: You can either use the standard JSR-107 (JCache) annotations or Spring's own
4041-
caching annotations transparently. We strongly advise you however to not mix and match
4042-
them.
4039+
This example demonstrates the use of caching on a potentially costly operation. Before
4040+
invoking `computePiDecimal`, the abstraction will look for an entry in the `piDecimals`
4041+
cache matching the `i` argument. If an entry is found, the content in the cache is
4042+
immediately returned to the caller and the method is not invoked. Otherwise, the method is
4043+
invoked and the cache is updated before returning the value.
4044+
4045+
NOTE: You can also use the standard JSR-107 (JCache) annotations (e.g. `@CacheResult`)
4046+
transparently. We strongly advise you however to not mix and match them.
40434047

40444048
TIP: It is also possible to {spring-reference}/#cache-annotations-put[update] or
40454049
{spring-reference}/#cache-annotations-evict[evict] data from the cache transparently.
@@ -4053,6 +4057,13 @@ materialized by the `org.springframework.cache.Cache` and
40534057
suitable `CacheManager` according to the implementation as long as the caching support is
40544058
enabled via the `@EnableCaching` annotation.
40554059

4060+
TIP: If you do not add any specific cache library, Spring Boot will auto-configure a
4061+
<<boot-features-caching-provider-simple,Simple provider>> that uses simple maps in
4062+
memory. When a cache is required for an operation (i.e. `piDecimals` in the example
4063+
above), the provider will create it on-the-fly for you. When you have made up your mind
4064+
about the cache provider to use, please make sure to read its documentation to figure out
4065+
how to configure the caches that your application defines.
4066+
40564067
NOTE: If you are using the cache infrastructure with beans that are not interface-based,
40574068
make sure to enable the `proxyTargetClass` attribute of `@EnableCaching`.
40584069

@@ -4327,7 +4338,14 @@ auto-configuration.
43274338
==== Simple
43284339
If none of these options worked out, a simple implementation using `ConcurrentHashMap`
43294340
as cache store is configured. This is the default if no caching library is present in
4330-
your application.
4341+
your application. Caches are created on-the-fly by default but you can restrict the list
4342+
of available caches using the `cache-names` property. For instance, you you want only a
4343+
`foo` and `bar` caches:
4344+
4345+
[source,properties,indent=0]
4346+
----
4347+
spring.cache.cache-names=foo,bar
4348+
----
43314349

43324350

43334351

0 commit comments

Comments
 (0)