src/Spiritix/LadaCache/QueryHandler.php
public function cacheQuery($queryClosure)
    {
        $this->constructCollector();

        // Make sure to reset the sub query tags already here
        // Otherwise we'll get into trouble if caching is disabled for main query but not for subquery
        $subQueryTags = $this->subQueryTags;
        $this->subQueryTags = [];

        /* @var Reflector $reflector */
        $reflector = new Reflector($this->builder);

        /* @var Manager $manager */
        $manager = new Manager($reflector);

        // If cache is disabled, abort already here to save time
        if (!$manager->shouldCache()) {
            return $queryClosure();
        }

        /* @var Hasher $hasher */
        $hasher = new Hasher($reflector);

        /* @var Tagger $tagger */
        $tagger = new Tagger($reflector);

        $result = null;
        $key = $hasher->getHash();
        $tags = array_unique(array_merge($tagger->getTags(), $subQueryTags));

        // Check if a cached version is available
        if ($this->cache->has($key)) {
            $result = $this->cache->get($key);
        }

        $action = ($result === null) ? 'Miss' : 'Hit';

        // If not, execute the query closure and cache the result
        if ($result === null) {
            $result = $queryClosure();
            $this->cache->set($key, $tags, $result);
        }

        $this->destructCollector($reflector, $tags, $key, $action);

        return $result;
    }
public function cacheQuery($queryClosure)
    {
        $this->constructCollector();

        // Make sure to reset the sub query tags already here
        // Otherwise we'll get into trouble if caching is disabled for main query but not for subquery
        $subQueryTags = $this->subQueryTags;
        $this->subQueryTags = [];

        /* @var Reflector $reflector */
        $reflector = new Reflector($this->builder);

        /* @var Manager $manager */
        $manager = new Manager($reflector);

        // If cache is disabled, abort already here to save time
        if (!$manager->shouldCache()) {
            return $queryClosure();
        }

        /* @var Hasher $hasher */
        $hasher = new Hasher($reflector);

        /* @var Tagger $tagger */
        $tagger = new Tagger($reflector);

        $result = null;
        $key = $hasher->getHash();
        $tags = array_unique(array_merge($tagger->getTags(), $subQueryTags));

        // Check if a cached version is available
        if ($this->cache->has($key)) {
            $result = $this->cache->get($key);
        }

        $action = ($result === null) ? 'Miss' : 'Hit';

        // If not, execute the query closure and cache the result
        if ($result === null) {
            $result = $queryClosure();
            $this->cache->set($key, $tags, $result);
        }

        $this->destructCollector($reflector, $tags, $key, $action);

        return $result;
    }
public function cacheQuery ( $ queryClosure ) { $ this -> constructCollector ( ) ; // Make sure to reset the sub query tags already here // Otherwise we'll get into trouble if caching is disabled for main query but not for subquery $ subQueryTags = $ this -> subQueryTags ; $ this -> subQueryTags = [ ] ; /* @var Reflector $reflector */ $ reflector = new Reflector ( $ this -> builder ) ; /* @var Manager $manager */ $ manager = new Manager ( $ reflector ) ; // If cache is disabled, abort already here to save time if ( ! $ manager -> shouldCache ( ) ) { return $ queryClosure ( ) ; } /* @var Hasher $hasher */ $ hasher = new Hasher ( $ reflector ) ; /* @var Tagger $tagger */ $ tagger = new Tagger ( $ reflector ) ; $ result = null ; $ key = $ hasher -> getHash ( ) ; $ tags = array_unique ( array_merge ( $ tagger -> getTags ( ) , $ subQueryTags ) ) ; // Check if a cached version is available if ( $ this -> cache -> has ( $ key ) ) { $ result = $ this -> cache -> get ( $ key ) ; } $ action = ( $ result === null ) ? 'Miss' : 'Hit' ; // If not, execute the query closure and cache the result if ( $ result === null ) { $ result = $ queryClosure ( ) ; $ this -> cache -> set ( $ key , $ tags , $ result ) ; } $ this -> destructCollector ( $ reflector , $ tags , $ key , $ action ) ; return $ result ; }
Caches a query and returns its result.

@param callable $queryClosure A closure which executes the query and returns the result

@return array
Caches a query and returns its result .