Skip to content

Commit 43fb99a

Browse files
committed
Merge branch '1.5.x'
2 parents e0d5c44 + 652a5e7 commit 43fb99a

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
@@ -4013,24 +4013,28 @@ relevant annotation to its method:
40134013

40144014
[source,java,indent=0]
40154015
----
4016-
import javax.cache.annotation.CacheResult;
4017-
4016+
import org.springframework.cache.annotation.Cacheable
40184017
import org.springframework.stereotype.Component;
40194018
40204019
@Component
40214020
public class MathService {
40224021
4023-
@CacheResult
4022+
@Cacheable("piDecimals")
40244023
public int computePiDecimal(int i) {
40254024
// ...
40264025
}
40274026
40284027
}
40294028
----
40304029

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

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

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

@@ -4290,7 +4301,14 @@ auto-configuration.
42904301
==== Simple
42914302
If none of these options worked out, a simple implementation using `ConcurrentHashMap`
42924303
as cache store is configured. This is the default if no caching library is present in
4293-
your application.
4304+
your application. Caches are created on-the-fly by default but you can restrict the list
4305+
of available caches using the `cache-names` property. For instance, you you want only a
4306+
`foo` and `bar` caches:
4307+
4308+
[source,properties,indent=0]
4309+
----
4310+
spring.cache.cache-names=foo,bar
4311+
----
42944312

42954313

42964314

0 commit comments

Comments
 (0)