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

第 32 章 Spring boot with Caching

目录

32.1. maven
32.1.1. Redis
32.2. 启用缓存 @EnableCaching
32.3. 设置缓存 @Cacheable
32.3.1. 多参数处理
32.3.2. 对象参数
32.3.3.
32.3.4. 参数索引
32.3.5. 自动生成 key
32.3.6. SpEL表达式
32.3.7. 排除 null 结果
32.3.8. 排除 empty
32.4. 更新缓存 @CachePut
32.5. 删除缓存 @CacheEvict
32.6. 组合操作 @Caching
32.7. 解决Expire 和 TTL 过期时间
32.8. Cannot serialize

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

32.1. maven

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

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