Caching for record collections based on compiled query