Execute code before cache is cleared I want to execute code before cache is cleared, for example for the menu cache:

// Clear menu cache
$cache = \Drupal::cache('menu');
$cache-&gt;deleteAll();


I want to intervene when the cache clear is called, right before it is deleted. I've read the documentation on Drupal::cache and the Cache API but didn't find a solution. Do note that I want to do this using core code only, no contributed modules.
It isn't clean but I'm able to do this with hook_cache_flush. It's called when a cache clear has been called, before the cache has been cleared.