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

第 59 章 Spring boot with Caching

目录

59.1. maven
59.1.1. Redis
59.2. 启用缓存 @EnableCaching
59.3. 设置缓存 @Cacheable
59.3.1. 多参数处理
59.3.2. 对象参数
59.3.3.
59.3.4. 参数索引
59.3.5. 自动生成 key
59.3.6. SpEL表达式
59.3.7. 排除 null 结果
59.3.8. 排除 empty
59.4. 更新缓存 @CachePut
59.5. 删除缓存 @CacheEvict
59.6. 组合操作 @Caching
59.7. 解决Expire 和 TTL 过期时间
59.8. Cannot serialize

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

59.1. maven

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

59.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