Spring Boot - Cacheable Toggle
Property based toggle to enable/disable caching
private boolean toggleActive;
public boolean isToggleActive() {
return toggleActive;
}
@Value("${service.cache.cache_store.enabled:false}")
public void setToggleActive(boolean toggleActive) {
this.toggleActive = toggleActive;
}
@Cacheable(cacheNames = "cache_store", condition = "#root.target.isToggleActive()", unless = "#result==null", key = "#key1+'-'+#key2")
public MyObject myCachedWithToggleFunction(String key1, String key2) {
// do fun stuff
MyObject o = new MyObject("key1","key2");
//return
return o;
}
service:
cache:
cache_store:
enabled: false
Last modified: 12 March 2024