|
15 | 15 |
|
16 | 16 | == Before you Begin |
17 | 17 |
|
18 | | -- JDK 1.8+ |
19 | | -- Apache Maven 3.2+ |
| 18 | +- JDK 17+ |
| 19 | +- Apache Maven 3.8+ |
20 | 20 |
|
21 | 21 | == Spring Boot Application |
22 | 22 |
|
23 | 23 | To use caching in your Spring Boot application, you need to: |
24 | 24 |
|
25 | 25 | - add `org.springframework.boot:spring-boot-starter-cache` dependency |
26 | | -- add `@EnableCaching` annotation to your main class |
27 | | -- add `@Cacheable("books")` annotation to every method you want to cache |
| 26 | +- add `@EnableCaching` annotation to your main configuration class |
| 27 | +- add `@Cacheable("X")` annotation to every method you want to cache, where X will be the name of the cache - eg. "books" |
28 | 28 |
|
29 | 29 | For more explanation on the Spring Boot cache topic, please check the official Spring Guide: https://spring.io/guides/gs/caching/[Caching Data with Spring]. |
30 | 30 |
|
@@ -85,7 +85,8 @@ We want to use Hazelcast as the cache manager. The good news is that all you hav |
85 | 85 | ---- |
86 | 86 | <dependency> |
87 | 87 | <groupId>com.hazelcast</groupId> |
88 | | - <artifactId>hazelcast-all</artifactId> |
| 88 | + <artifactId>hazelcast</artifactId> |
| 89 | + <version>5.5.0</version> |
89 | 90 | </dependency> |
90 | 91 | ---- |
91 | 92 |
|
@@ -130,15 +131,17 @@ Members {size:1, ver:1} [ |
130 | 131 | You can test the application by executing the following command: |
131 | 132 |
|
132 | 133 | ---- |
133 | | -curl localhost:8080/books/12345 |
| 134 | +curl -w '\nTotal: %{time_total}s\n' localhost:8080/books/12345 |
134 | 135 | Sample Book Name |
| 136 | +Total: 3.090784s |
135 | 137 | ---- |
136 | 138 |
|
137 | 139 | The first time you execute this command, it should take some time to get the response. However, when you try it again, it should be instant. That means that the cache is used. |
138 | 140 |
|
139 | 141 | ---- |
140 | | -curl localhost:8080/books/12345 |
| 142 | +curl -w '\nTotal: %{time_total}s\n' localhost:8080/books/12345 |
141 | 143 | Sample Book Name |
| 144 | +Total: 0.009667s |
142 | 145 | ---- |
143 | 146 |
|
144 | 147 | == See Also |
|
0 commit comments