Chapter 14 Spring Cache caching solution

1, Cache Introduction

Spring Cache Cache is a framework solution, SpringBoot effective for Cache made a simplified, annotation can be operated only need to use our stored in the cache area (including memory area, the cache server Redis) of cached data (table reservation form, user table)

Application of the system needs to cache data infrequently changed by the Cache, to improve system performance and increase system throughput. Avoid direct access to the database system and other low-speed storage area, the cached data is typically stored in faster access low-latency memory or a server memory access speed.

 

Spring Boot Integrated Cache steps

1, as introduced in dependence of Maven pom.xml

1 <!-- spring cache -->
2 <dependency>
3        <groupId>org.springframework.boot</groupId>
4        <artifactId>spring-boot-starter-cache</artifactId>
5 </dependency>

2, is provided in the cache middleware type application.properties

1  <! - type configuration cache middle price -> 
2 spring.cache.type = Redis (MonDB, the Simple, none)

3, open the start Cache class

1 @EnableCaching
2 @SpringBootApplication
3 public class BookSystemMicroServices {
4     public static void main(String[] args) {
5         SpringApplication.run(BookSystemMicroServices.class, args);
6     }
7 }

 

 

2, annotation-driven cache

Once configured SpringBoot cache, you can use the cache annotations Bean Spring managed, it can usually be placed directly on the Service class method
  • @Cacheable acting on the method, the reading operation trigger buffer
  • @CacheEvict role in the process trigger a cache miss operations
  • @CachePut role in the process triggered cache update operations
  • @Cache role in approach, integrated above various operations, there are scenarios in call traffic will trigger a variety of caching operations
  • @CacheConfig, set the current caching on the class some public settings

 

Guess you like

Origin www.cnblogs.com/zouzhu1998/p/12015952.html