Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 34 章 Spring boot with Caching

目录

34.1. maven
34.1.1. Redis
34.2. 启用 Cache
34.3. @Cacheable 的用法
34.3.1. SpEL表达式
34.3.2. 排除 null 结果
34.3.3. 排除 empty
34.4. @CachePut 用法
34.5. 清空缓存
34.6. @Caching
34.7. 解决Expire 和 TTL 过期时间

https://docs.spring.io/spring-boot/docs/current/reference/html/io.html#io.caching.provider.redis

34.1. maven

            
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>			
            
		

34.1.1. Redis

使用 Redis

        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-cache</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>        
        
			
    	
spring.data.redis.host=cch.netkiller.cn
spring.data.redis.port=6379
spring.data.redis.password=passw0rd
spring.data.redis.database=10
spring.data.redis.timeout=30000
spring.data.redis.lettuce.pool.max-active=8
spring.data.redis.lettuce.pool.max-wait=-1
spring.data.redis.lettuce.pool.max-idle=8
spring.data.redis.lettuce.pool.min-idle=0

spring.cache.type=redis
spring.cache.redis.time-to-live=3600000
spring.cache.redis.cache-null-values=true