Spring @Cacheable default TTL

后端 未结 5 823
爱一瞬间的悲伤
爱一瞬间的悲伤 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:53

    Spring @Cacheable does not have any configurable option to set TTL for the cache though you can build it using @CacheEvict and @Scheduled, as follows:

    @CacheEvict(allEntries = true, cacheNames = { "cache_1", "cache_2" })
    @Scheduled(fixedDelay = 30000)
    public void cacheEvict() {
    }
    

    You can find detailed solution/explanation here - Setting TTL for @Cacheable – Spring.

提交回复
热议问题