I am trying to temporarily disable (by disable I mean: act as if caching was turned off entirely) a set of cache2k caches and there seems to be no way to do this with the default implementation at "runtime" (and by runtime I mean after the cache has been created and potentially populated). So I thought I would provide a new Cache (possibly using the existing cache implementation along with org.cache2k.ForwardingCache
and just wrapping each call to act as I would expect if disabled). Please note that I am not using any loader functionality (and would like not to).
How do I register a new cache implementation within cache2k? Is there a better way to do this without using a loader?
Ideally I would like to do something like this:
public void enableCaching() {
CacheManager.getInstance().getActiveCaches().forEach(cache -> {
cache.enable();
});
}
public void disableCaching() {
CacheManager.getInstance().getActiveCaches().forEach(cache -> {
cache.clear();
cache.disable();
});
}