Knowledge Point: springboot used in cache and redis
(1) springboot, the integrated cache, we just need to, in the entrance class plus @EnableCaching to open the cache
For example: in the service layer and CacheEvict @Cacheable
// add the cache
@Cacheable ( cacheNames = "TestCACHE" , Key = "#root. MethodName + '_' + #id")
public the Map <String , Object> testSetCache (Integer ID) {
the Map <String , Object> = User userMapper.findUserById (ID) ;
return User ;
}
// clear the cache
@CacheEvict ( cacheNames = "TestCACHE" , allEntries = to true)
public Boolean testEvictCache () {
return to true;
}
(2) is introduced redis dependent, data cache will redis into the database and then fetch the data from redis
a. dependency introduced
<!--加入redis依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
b.application.yml provided connections arranged redis
redis:
Host: 192.10.21.237
Port: 6379 Database: . 5 password: timeout: 1800000 jedis: the pool: max-IDLE: 10 min-IDLE: 0 max-Active: 10 max the wait-: 1000 stored data redis following problems: garbled key will summarize the principles 1.cache other usage 2.springboot the following reference: https: //blog.csdn.net/weixin_36279318/article/details/82820880