Implemented a Document cache for the QueryFunction