Add instrumentation to query cache

[fixes #3502]