Spring @Cacheable default TTL

后端 未结 5 827
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-14 14:09

I generally use the @Cacheable with a cache config in my spring-boot app and set specific TTL (time to live) for each cache.

I recently inherited a spring b

5条回答
  •  甜味超标
    2021-02-14 14:59

    With spring boot, I was able to achieve success with this:

    First, you need to add spring-boot-starter-data-redis artifact to your POM file.

     
        org.springframework.boot 
        spring-boot-starter-data-redis 
    
    

    After this, you need to add the required the following configurations in your application.properties files:

    #------ Redis Properties -------------
    spring.cache.type=redis
    spring.redis.host=127.0.0.1
    spring.redis.port=6379
    spring.cache.redis.time-to-live=600000
    

    The property to set is spring.cache.redis.time-to-live (value is in milliseconds. 10 mins was set in this case). With this, @Cacheable works with the set default TTL.

提交回复
热议问题