support callbacks on clear cache, support custom callbacks

Fixes #5623