1

Considering the below service how can I dynamically modify the cache configuration with the /actuator/refresh endpoint

@Service
@Slf4j
public class GreetingService {

    @Cacheable("greeting")
    public String greet(String name) {
       log.info("Greeting: {}", name);
       return "Hello " + name ;
    }
}

with the following default configuration

spring
  cache:
    caffeine:
      spec: maximumSize=100,expireAfterAccess=600s

Let's say setting to maximumSize=50,expireAfterAccess=300s

Adding @RefreshScope in GreetingService does not work. Somehow I need to instruct Spring Boot to re-create the CacheManager?

I have a supporting project here:

  1. https://github.com/altfatterz/refreshscope-demo
  2. https://github.com/altfatterz/refreshscope-demo-config

Thanks.

Zoltan Altfatter
  • 802
  • 2
  • 11
  • 25
  • Caffeine does support dynamically updating the [configuration](https://github.com/ben-manes/caffeine/wiki/Policy), if that helps. This can only modify already enabled features and probably isn't exposed in Spring's support. – Ben Manes Jan 14 '19 at 17:33
  • Thanks Ben for the link. – Zoltan Altfatter Jan 15 '19 at 10:04

1 Answers1

0

You are using actuator so probably you have also cache actuator present. So for your case test with this command: curl 'http://server:port/actuator/caches/greeting' -i -X DELETE

note: I didn't tested that, it's just an idea

bilak
  • 4,526
  • 3
  • 35
  • 75
  • 1
    yes, that is correct, but I wanted to check if with the @RefreshScope it will work or not if there are cache configuration changes – Zoltan Altfatter Jan 15 '19 at 10:05