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

第 34 章 Spring boot with Caching

目录

34.1. maven
34.1.1. Redis
34.2. 启用缓存 @EnableCaching
34.3. 设置缓存 @Cacheable
34.3.1. 多参数处理
34.3.2. 对象参数
34.3.3.
34.3.4. 参数索引
34.3.5. 自动生成 key
34.3.6. SpEL表达式
34.3.7. 排除 null 结果
34.3.8. 排除 empty
34.4. 更新缓存 @CachePut
34.5. 删除缓存 @CacheEvict
34.6. 组合操作 @Caching
34.7. 解决Expire 和 TTL 过期时间
34.8. Cannot serialize

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=32
spring.data.redis.lettuce.pool.max-wait=-1
spring.data.redis.lettuce.pool.max-idle=8
spring.data.redis.lettuce.pool.min-idle=2
spring.cache.type=redis
spring.cache.redis.key-prefix=spring:
spring.cache.redis.use-key-prefix=true
spring.cache.redis.time-to-live=604800000
spring.cache.redis.cache-null-values=false