Is it possible to set a different specification per cache using caffeine in spring boot?

后端 未结 3 504
Happy的楠姐
Happy的楠姐 2021-02-02 10:03

I have a simple sprint boot application using spring boot 1.5.11.RELEASE with @EnableCaching on the Application Configuration class.

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 10:19

    This is your only chance:

    @Bean
    public CaffeineCache cacheA() {
        return new CaffeineCache("CACHE_A",
                Caffeine.newBuilder()
                        .expireAfterAccess(1, TimeUnit.DAYS)
                        .build());
    }
    
    @Bean
    public CaffeineCache cacheB() {
        return new CaffeineCache("CACHE_B",
                Caffeine.newBuilder()
                        .expireAfterWrite(7, TimeUnit.DAYS)
                        .recordStats()
                        .build());
    }
    

    Just expose your custom caches as beans. They are automatically added to the CaffeineCacheManager.

提交回复
热议问题