adding on_cache_flush event

Adding a simple event dispatch upon cache flush (from the application), and hereby fixing #1685
This should be a trivial merge.

Here we are, this request is now clean enough :)