Mongolid\Cursor\CacheableCursor::getCursor PHP Method

getCursor() protected method

If it does not exists yet, create it using the $collection, $command and $params given. The difference between the CacheableCursor and the normal Cursor is that the Cacheable stores all the results within itself and drops the Driver Cursor in order to be serializable.
protected getCursor ( ) : Traversable
return Traversable
    protected function getCursor() : Traversable
    {
        // Returns original (non-cached) cursor
        if ($this->ignoreCache || $this->position >= self::DOCUMENT_LIMIT) {
            return $this->getOriginalCursor();
        }
        // Returns cached set of documents
        if ($this->documents) {
            return $this->documents;
        }
        // Check if there is a cached set of documents
        $cacheComponent = Ioc::make(CacheComponentInterface::class);
        $cacheKey = $this->generateCacheKey();
        if ($this->documents = $cacheComponent->get($cacheKey, null)) {
            return $this->documents = new ArrayIterator($this->documents);
        }
        // Stores the original "limit" clause of the query
        $this->storeOriginalLimit();
        // Stores the documents within the object and cache then for later use
        $this->documents = [];
        foreach (parent::getCursor() as $document) {
            $this->documents[] = $document;
        }
        $cacheComponent->put($cacheKey, $this->documents, 0.6);
        // Drops the unserializable DriverCursor.
        $this->cursor = null;
        // Return the documents iterator
        return $this->documents = new ArrayIterator($this->documents);
    }