Trying to make a cached iterator for queries