1
votes

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.

1
Caffeine does support dynamically updating the configuration, if that helps. This can only modify already enabled features and probably isn't exposed in Spring's support. - Ben Manes
Thanks Ben for the link. - Zoltan Altfatter

1 Answers

0
votes

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