query based caching