Fix query cache bug