Save query cache

@param string $sql
@param mixed $result
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;
        }
    }
678439
protected function cacheGet(string $sql, array $values = null, string $index = null){

		if($this->cache instanceof CacheInterface){
			return $this->cache->get($this->cacheKey($sql, $values, $index));
		}

		return false; // @codeCoverageIgnore
	}
24649
protected function after_update($result) {
        $cache = \cache::make('tool_dataprivacy', 'purpose');
        $cache->set($this->get('id'), $this->to_record());
    }
851491
function setViewResult( $result, $view = '' )
    {
        if ( $view == '' )
            $view = $this->currentView();
        $this->ViewResult[$view] = $result;
    }
913628
protected function after_delete($result) {
        global $DB;
        if (!$result) {
            return;
        }

        // Resolving sortorder holes left after delete.
        $table = '{' . self::TABLE . '}';
        $sql = "UPDATE $table SET sortorder = sortorder -1  WHERE  competencyframeworkid = ? AND parentid = ? AND sortorder > ?";
        $DB->execute($sql, array($this->get('competencyframeworkid'), $this->get('parentid'), $this->get('sortorder')));
    }
288558
function query($sql)
    {
        $res = false;

        for ($i = 0; $i < 2; $i++)
        {
            $res = mysql_query($sql, $this->conn);
            if ($res === false)
            {
                if (mysql_errno($this->conn) == 2006 or mysql_errno($this->conn) == 2013 or (mysql_errno($this->conn) == 0 and !$this->ping()))
                {
                    $r = $this->checkConnection();
                    if ($r === true)
                    {
                        continue;
                    }
                }
                \Swoole\Error::info(__CLASS__." SQL Error", $this->errorMessage($sql));
                return false;
            }
            break;
        }

        if (!$res)
        {
            Swoole\Error::info(__CLASS__." SQL Error", $this->errorMessage($sql));
            return false;
        }
        if (is_bool($res))
        {
            return $res;
        }
        return new MySQLRecord($res);
    }
935634
function cache($query, $result) {
        if ($this->isSelectStatement($query) === TRUE) $this->queries[$query] = $result;
        else return(FALSE);
        return(TRUE);
    }
155786
public function create(Result $result)
    {
        $this->om->persist($result);
        $this->om->flush();

        return $result;
    }
292843
public function update($sqlQuery = false)
    {
        $field = func_get_args();
        if(func_num_args() == 0) {
            echo 'no data to save'; //no argument
            exit;
        }
        elseif(func_num_args() == 1) {
            if(is_array($field[0])) {
                $data = $field[0]; //single array with all data
            }
            else {
                $data = $field[0]; //sql fraction
            }
        }
        else {
            echo 'invalid data';
            exit;
        }
        $sql = $this->buildQuery('update', $data);
        if($sqlQuery === true) {
            return $this->getQuery();
        }
        $result = $this->executeQuery($sql);
        return $result;
    }
460907
public function saveCache($sql, $bind = [], $value) {
        $redis = Cache::redis();
        if (!$redis) {
            //没有使用 redis 不支持二级缓存
            return;
        }
        $key = $this->cacheKey($sql, $bind);
        $cache_name = $this->cacheName($sql);
        Cache::hashSet($cache_name, $key, $value);
        $tables = $this->getTableNames($sql);
        foreach ($tables as $t) {
            $redis->sAdd(static::$second_table_prefix . $t, $cache_name);
        }
    }
1250373
protected function query ( $sql )
	{
		$sql = $this->sql_printf(func_get_args());
		if (!($res = mysqli_query( $this->conn, $sql)))
		{
			$this->sql_errcheck($sql);
		}
		if (!is_bool($res))
		{
			((mysqli_free_result($res) || (is_object($res) && (get_class($res) == "mysqli_result"))) ? true : false);
		}
	}
505439
public function add($data, $sqlQuery = false)
    {
        if(!is_array($data) || count($data) == 0) {
            echo 'no data to save'; //no argument
            exit;
        }
        $sql = $this->buildQuery('insert', $data);
        if($sqlQuery === true) {
            return $this->getQuery();
        }
        $result = $this->executeQuery($sql);
        return $result;
    }
667524
protected function cacheSet(string $sql, $result, array $values = null, string $index = null, int $ttl = null):bool{

		if($this->cache instanceof CacheInterface){
			return $this->cache->set($this->cacheKey($sql, $values, $index), $result, $ttl);
		}

		return false; // @codeCoverageIgnore
	}
70668
public static function writeQueryCache(Garp_Model_Db $model, $key, $results) {
        $cache = new Garp_Cache_Store_Versioned($model->getName() . '_version');
        $cache->write($key, $results);
    }
1230529
public function Query($Sql) {
		if($this->CaptureOnly) {
			if(!property_exists($this->Database, 'CapturedSql'))
				$this->Database->CapturedSql = array();
			$this->Database->CapturedSql[] = $Sql;
			return TRUE;
		} else {
			$Result = $this->Database->Query($Sql);
			return $Result;
		}
	}
884659
protected function execute($sql)
    {
        $this->lastQuery = $sql;

        $this->debugLog(sprintf('Executing SQL: %s', $sql));

        $this->sqlStatement = $this->getConnection()->prepare($sql, []);
        $this->sqlStatement->execute();
        $this->lastId = $this->connection->lastInsertId(sprintf('%s_id_seq', $this->getEntity()));

        // If their is an id, save it!
        if ($this->lastId) {
            $this->handleLastId($this->getEntity(), $this->lastId);
        }

        return $this->sqlStatement;
    }
1270663
private function doAfterQuery($result, $methodName, $arguments)
    {
        $traits = $this->getUsedTraits();

        if (in_array(CacheResults::class, $traits)) {
            // Reset caching to enabled in case it has just been disabled.
            $this->caching = true;
        }

        if (in_array(ThrowsHttpExceptions::class, $traits)) {

            if ($this->shouldThrowHttpException($result, $methodName)) {
                $this->throwNotFoundHttpException($methodName, $arguments);
            }

            $this->exceptionsDisabled = false;
        }

        return $result;
    }