Add support for caching QueryIds.