MNG-5677 hooks to allow fine-grained cache management

Also fixed broken cache #flush() and missing #dispose() in
couple of places.

Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>