Caching
Caching data from services plays a crucial role in improving the performance and scalability of applications. In this section, we will look at the implementation options that Spring Boot provides.
Spring provides a caching abstraction based on annotations. We will start with using Spring caching annotations. Later, we will introduce JSR-107 caching annotations and compare them with Spring abstractions.
Spring-boot-starter-cache
Spring Boot provides a starter project for caching spring-boot-starter-cache
. Adding this to an application brings in all the dependencies to enable JSR-107 and Spring caching annotations. The following code snippet shows the dependency details for spring-boot-starter-cache
. Let's add this to our file pom.xml
:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency>
Enabling Caching
Before we can start using caching, we need to enable caching...