Checks the cache to see if this query exists and returns it. If it's
not in the cache then the query is run, stored and then returned.

@return Result The result of the query.
340629
public function execute()
    {
        static $apcPrefix = null;
        if($apcPrefix === null) {
            $apcPrefix = function_exists('apcu_fetch') ? 'apcu' : 'apc';
        }

        // Generate a cache key by comparing our parameters to see if we've
        // made this query before
        $key = $this->getParameterHash() . $this->getFileHash();

        // Try and fetch a cached result object from APC
        $funcName = $apcPrefix . '_fetch';
        $success  = false;
        $result   = $funcName($key, $success);

        // If the result isn't in the cache then we run the real query
        if (!$success) {
            $result = parent::execute();
            $funcName = $apcPrefix . '_store';
            $funcName($key, $result);
        }

        return $result;
    }
90722
public void clearCachedResult() {
    conditions.assembleParameters();
    Map<String, String> query = conditions.getParameters();
    String cacheKey = QueryResultCache.generateKeyForQueryCondition(getClassName(), query);
    QueryResultCache.getInstance().clearCachedFile(cacheKey);
  }
414331
public boolean result(final Object iRecord) {
    final ORecordAbstract<?> record = (ORecordAbstract<?>) iRecord;

    if (record.getIdentity().isValid()) {
      // RESET VERSION TO DISABLE MVCC AVOIDING THE CONCURRENT EXCEPTION IF LOCAL CACHE IS NOT UPDATED
      record.setVersion(-1);
      record.delete();
      recordCount++;
      return true;
    }
    return false;
  }
549457
public function result()
    {
        $this->fill();
        return $this->results->isEmpty() ? null : $this->results->dequeue();
    }
88087
public function getResults()
    {
        if (null === $this->results) {
            $queryKey = method_exists($this->getQuery(), 'getQueryKey') ? $this->getQuery()->getQueryKey() : null;
            if ($queryKey) {
                $newQueryKey = sprintf('%s offset %s limit %s', $queryKey, $this->getQuery()->getOffset(), $this->getQuery()->getLimit());
                $this->getQuery()->setQueryKey($newQueryKey);
            }
            
            $this->results = $this->getQuery()
                ->find($this->con)
            ;
        }

        return $this->results;
    }
235412
public function count()
    {
        if ($this->countCached === null) {
            $pageSize = $this->pageSize;
            $this->pageSize = 1;
            $this->makeQuery(1);
            $this->pageSize = $pageSize;
        }

        return $this->countCached;
    }
1089022
public function canCache()
    {
        // Check if the response is cacheable based on the code
        if (!in_array((int) $this->getStatusCode(), self::$cacheResponseCodes)) {
            return false;
        }

        // Make sure a valid body was returned and can be cached
        if ((!$this->getBody()->isReadable() || !$this->getBody()->isSeekable())
            && ($this->getContentLength() > 0 || $this->getTransferEncoding() == 'chunked')) {
            return false;
        }

        // Never cache no-store resources (this is a private cache, so private
        // can be cached)
        if ($this->getHeader('Cache-Control') && $this->getHeader('Cache-Control')->hasDirective('no-store')) {
            return false;
        }

        return $this->isFresh() || $this->getFreshness() === null || $this->canValidate();
    }
98020
public function query() {
    $adapter = $this->getAdapter();
    $sql = $this->getSql();
    // always update offset, since it's most likely not contained in the cache id
    $sql = preg_replace('/OFFSET\s+[0-9]+/i', 'OFFSET '.$this->getRawState(Select::OFFSET), $sql);
    $stmt = $adapter->getDriver()->getConnection()->prepare($sql);
    if (self::$logger->isDebugEnabled()) {
      self::$logger->debug("Execute statement: ".$sql);
      self::$logger->debug($this->getParameters(true));
    }
    return $stmt->execute($this->getParameters(true))->getResource();
  }
12678
final protected function cache_query($sql, $result){
        if( isset($this->query_cache[$sql]) ){
            $this->query_cache[$sql] = $result;
        }elseif( count($this->query_cache) >= $this->cache_limit ){
            // Remove oldest cache
            array_shift($this->query_cache);
            // save query
            $this->query_cache[$sql] = $result;
        }
    }
365261
def result
      if @cache[:checks].new_objects?
        @cache[:checks].stored_objects.each do |c|
          @result = Result.new(c.sample) unless c.success?
        end
      end

      @result
    end
1107085
public function getResult () : Result
    {
        // Cache
        if ( $this->_Result !== null ) :
            return $this->_Result;
        endif;

            //////

        // Sort pairwise
        $this->_PairwiseSort = $this->pairwiseSort();

        // Ranking calculation
        $this->makeArcs();

        // Make Stats
        $this->_Stats['tally'] = $this->_PairwiseSort;
        $this->_Stats['arcs'] = $this->_Arcs;

        // Make Result      
        return $this->_Result = $this->createResult($this->makeResult());
    }
100182
public function getStatus(): Result
    {
        $result = new Result();
        try {
            $this->connect();
            $connection = DriverManager::getConnection(['pdo' => $this->databaseHandle]);
        } catch (\Exception $exception) {
            $result->addError(new Error($exception->getMessage(), $exception->getCode(), [], 'Connection failed'));
            return $result;
        }
        try {
            $cacheTableExists = $connection->getSchemaManager()->tablesExist([$this->cacheTableName]);
            $tagsTableExists = $connection->getSchemaManager()->tablesExist([$this->tagsTableName]);
        } /** @noinspection PhpRedundantCatchClauseInspection */ catch (DBALException $exception) {
            $result->addError(new Error($exception->getMessage(), $exception->getCode(), [], 'Connection failed'));
            return $result;
        }
        $result->addNotice(new Notice((string)$connection->getDatabase(), null, [], 'Database'));
        $result->addNotice(new Notice((string)$connection->getDriver()->getName(), null, [], 'Driver'));

        if (!$cacheTableExists) {
            $result->addError(new Error('%s (missing)', null, [$this->cacheTableName], 'Table'));
        }
        if (!$tagsTableExists) {
            $result->addError(new Error('%s (missing)', null, [$this->tagsTableName], 'Table'));
        }
        if (!$cacheTableExists || !$tagsTableExists) {
            return $result;
        }
        $fromSchema = $connection->getSchemaManager()->createSchema();
        $schemaDiff = (new Comparator())->compare($fromSchema, $this->getCacheTablesSchema());
        try {
            $statements = $schemaDiff->toSaveSql($connection->getDatabasePlatform());
        } catch (DBALException $exception) {
            $result->addError(new Error($exception->getMessage(), $exception->getCode(), [], 'Connection failed'));
            return $result;
        }
        if ($statements !== []) {
            $result->addError(new Error('The schema of the cache tables is not up-to-date', null, [], 'Table schema'));
            foreach ($statements as $statement) {
                $result->addWarning(new Warning($statement, null, [], 'Required statement'));
            }
        }
        return $result;
    }
544592
public function getResult()
    {
        if ($this->map->currentModel->row instanceof Sql\DataObjects\Result\Row) {
            $criteria = $this->map->currentModel->row->offsetGet($this->map->currentPrimaryKey);
            $condition = [
                $this->map->intermediaryTable . '.' . $this->map->intermediaryCurrentForeignKey => $criteria,
            ];

            $this->map->intermediaryModel->qb
                ->select([
                    $this->map->referenceTable . '.*',
                ])
                ->from($this->map->intermediaryTable)
                ->join($this->map->referenceTable, implode(' = ', [
                    $this->map->referenceTable . '.' . $this->map->referencePrimaryKey,
                    $this->map->intermediaryTable . '.' . $this->map->intermediaryReferenceForeignKey,
                ]));

            if ($result = $this->map->intermediaryModel->findWhere($condition)) {
                return $result;
            }
        }

        return false;
    }
147287
public function exists(): bool
    {
        if ($this->caching == false) {
            return file_exists($this->getAbsoluteFilePath());
        }

        if ($this->exists == null) {
            $this->exists = file_exists($this->getAbsoluteFilePath());
        }

        return $this->exists;
    }
1288603
public function getQueryCacheDriver()
    {
        if (!$this->queryCacheDriver instanceof CacheProvider) {
            $this->queryCacheDriver = $this->getCacheDriver(
                (string) $this->getOption('query_cache_namespace'),
                $this->getOption('query_cache_driver')
            );
        }

        return $this->queryCacheDriver;
    }
113574
public <T> T asSingleResult() {
		T javaObject = null;
		String cacheKey = getCacheKey();
		if (isCacheable() && transaction == null) {
			Collection<Key> keys = getCacheManager().get(cacheNamespace, cacheKey);
			if (keys != null && keys.size() > 0) {
				Key key = keys.iterator().next();
				try {
					javaObject = (T) entityManager.get(key);
				} catch (EntityNotFoundException e) {
					throw new InconsistentCacheException("Entity Key " + key + " found in the cache but not in the Datastore");
				}
			}
		}
		if (javaObject == null) {
			Entity entity = getDatastoreService().prepare(query).asSingleEntity();
			if (entity == null) {
				throw new org.simpleds.exception.EntityNotFoundException("No " + getKind() + " found with " + getFilterPredicates());
			}
			javaObject = (T) entityManager.datastoreToJava(entity);
			if (isCacheable()) {
                populateCache(cacheKey, ImmutableList.of(entity.getKey()));
			}
		}
		return javaObject;

	}
1149467
public boolean hasCache() {
        if (isCache()) {
            return true;
        }
        if (CommonUtils.isNotEmpty(methods)) {
            for (MethodConfig methodConfig : methods.values()) {
                if (CommonUtils.isTrue(methodConfig.getCache())) {
                    return true;
                }
            }
        }
        return false;
    }