Fix for massive bug in query cache retrieval