自动初始化缓存
@access public
@param  array $options 配置数组
@param  bool  $force   强制更新
@return Driver
428886
public function init(array $options = [], bool $force = false): Driver
    {
        if (is_null($this->handler) || $force) {
            if (isset($options['type']) && 'complex' == $options['type']) {
                $default = $options['default'];
                $options = $options[$default['type']] ?? $default;
            }

            $this->handler = $this->connect($options);
        }

        return $this->handler;
    }
611340
public function execute(Query $query, array $options = [])
    {
        $result = $this->_executeQuery($query, $options);

        if ($this->getDriver() === null) {
            throw new \UnexpectedValueException(__('No driver has been defined'));
        }

        // Write to the logger when one has been defined
        if ($this->getDriver()->getLogger()) {
            $this->_logQuery($query, $this->getDriver()->getLogger());
        }

        return $result;
    }
426585
public function persist($force = false) {
        global $DB;

        if (!$this->dirty && !$force) {
            return $this;
        }

        if ($this->id) {
            $record = $this->to_record();
            $DB->update_record('tool_usertours_tours', $record);
        } else {
            $this->calculate_sortorder();
            $record = $this->to_record();
            unset($record->id);
            $this->id = $DB->insert_record('tool_usertours_tours', $record);
        }

        $this->reload();

        // Notify the cache that a tour has changed.
        cache::notify_tour_change();

        return $this;
    }
126944
public function createDriver($options = [])
    {
        $options = $this->optionsResolver->resolve($options);

        return new CollectionDriver($this->extensions, $options['collection'], $options['criteria']);
    }
947056
public static function getDsn(array $options = [], $driver = null)
    {
        if (!empty($options['dsn'])) {
            return $options['dsn'];
        }

        self::$options = $options;

        if (!$driver) {
            $driver = $options['driver'] ?? null;
        }

        if (!$driver) {
            throw new \LogicException('The driver name is required.');
        }

        if (!\is_callable([static::class, $driver])) {
            throw new \RuntimeException('The ' . $driver . ' driver is not supported.');
        }

        list($dsn, $replace) = static::$driver();

        $dsn = strtr($dsn, $replace);

        self::$options = [];

        return $dsn;
    }
1157132
public function delete($force = false)
    {
        if (!$this->isExists() || false === $this->trigger('before_delete', $this)) {
            return false;
        }

        $force = $force ?: $this->isForce();
        $name  = $this->getDeleteTimeField();

        if ($name && !$force) {
            // 软删除
            $this->data($name, $this->autoWriteTimestamp($name));

            $result = $this->isUpdate()->withEvent(false)->save();

            $this->withEvent(true);
        } else {
            // 读取更新条件
            $where = $this->getWhere();

            // 删除当前模型数据
            $this->db(false)
                ->where($where)
                ->removeOption('soft_delete')
                ->delete();
        }

        // 关联删除
        if (!empty($this->relationWrite)) {
            $this->autoRelationDelete();
        }

        $this->trigger('after_delete', $this);

        $this->exists(false);

        return true;
    }
865767
public function register($provider, $options = [], $force = false)
    {
        $instance = new $provider($this);
        if (method_exists($instance, 'register')) {
            $this->call([$instance, 'register']);
        }
        $this->providers[$provider] = $instance;
    }
641173
public function store(string $name = '', $force = false): Driver
    {
        if ('' !== $name && 'complex' == $this->config['type']) {
            return $this->connect($this->config[$name], $force);
        }

        return $this->init();
    }
1174075
public function getUpdates($force = FALSE) {
		if (!$force) {
			$result = $this->cache->get('updates');
			if ($result) {
				return $result;
			}
		}

		// Make sure we're logged in and have a valid access token.
		if (!$this->auth_token || !$this->username) {
			return FALSE;
		}

		$timestamp = parent::timestamp();
		$result = parent::post(
			'/all_updates',
			array(
				'timestamp' => $timestamp,
				'username' => $this->username,
			),
			array(
				$this->auth_token,
				$timestamp,
			)
		);

		if (!empty($result->updates_response)) {
			$this->auth_token = $result->updates_response->auth_token;
			$this->cache->set('updates', $result->updates_response);
			return $result->updates_response;
		}

		return $result;
	}
1206477
protected function resetLang($force = false)
    {
        if ($this->autoResetLang || $force) {
            $this->lang = null;
        }

        return $this;
    }
384627
public function read($force = false)
	{
		// initialize the session
		$this->data = array();
		$this->keys = array();
		$this->flash = array();
		$this->record = null;

		// get the session cookie
		$cookie = $this->_get_cookie();

		// if a cookie was present, find the session record
		if ($cookie and ! $force and isset($cookie[0]))
		{
			// read the session record
			$this->record = \DB::select()->where('session_id', '=', $cookie[0])->from($this->config['table'])->execute($this->config['database']);

			// record found?
			if ($this->record->count())
			{
				$payload = $this->_unserialize($this->record->get('payload'));
			}
			else
			{
				// try to find the session on previous id
				$this->record = \DB::select()->where('previous_id', '=', $cookie[0])->from($this->config['table'])->execute($this->config['database']);

				// record found?
				if ($this->record->count())
				{
					$payload = $this->_unserialize($this->record->get('payload'));
				}
				else
				{
					// cookie present, but session record missing. force creation of a new session
					logger('DEBUG', 'Error: Session cookie with ID "'.$cookie[0].'" present but corresponding record is missing');
					return $this->read(true);
				}
			}

			if ( ! isset($payload[0]) or ! is_array($payload[0]))
			{
				logger('DEBUG', 'Error: not a valid db session payload!');
			}
			elseif ($payload[0]['updated'] + $this->config['expiration_time'] <= $this->time->get_timestamp())
			{
				logger('DEBUG', 'Error: session id has expired!');
			}
			elseif ($this->config['match_ip'] and $payload[0]['ip_hash'] !== md5(\Input::ip().\Input::real_ip()))
			{
				logger('DEBUG', 'Error: IP address in the session doesn\'t match this requests source IP!');
			}
			elseif ($this->config['match_ua'] and $payload[0]['user_agent'] !== \Input::user_agent())
			{
				logger('DEBUG', 'Error: User agent in the session doesn\'t match the browsers user agent string!');
			}
			else
			{
				// session is valid, retrieve the payload
				if (isset($payload[0]) and is_array($payload[0])) $this->keys  = $payload[0];
				if (isset($payload[1]) and is_array($payload[1])) $this->data  = $payload[1];
				if (isset($payload[2]) and is_array($payload[2])) $this->flash = $payload[2];
			}
		}

		return parent::read();
	}
759217
public function update(bool $force, OutputInterface $output)
    {
        $newSchema = new Schema();
        $this->schemaDefinition->define($newSchema);
        $currentSchema = $this->db->getSchemaManager()->createSchema();

        $migrationQueries = $currentSchema->getMigrateToSql($newSchema, $this->db->getDatabasePlatform());

        $this->db->transactional(function () use ($migrationQueries, $force, $output) {
            foreach ($migrationQueries as $query) {
                $output->writeln(sprintf('Running <info>%s</info>', $query));
                if ($force) {
                    $this->db->exec($query);
                }
            }
            if (empty($migrationQueries)) {
                $output->writeln('<info>The database is up to date</info>');
            }
        });

        if (!$force) {
            $output->writeln('<comment>No query was run, use the --force option to run the queries</comment>');
        } else {
            $output->writeln('<comment>Queries were successfully run against the database</comment>');
        }
    }
770680
public function rewire($force=false): self
    {
        if(!$force && $this->rewired)
            return $this;

        Hooks::setup($this);

        $this->on("modified", [$this, "persist"]);
        $this->on("edge.created", [$this, "onEdgeCreated"]);
        $this->on("edge.connected", [$this, "onEdgeConnected"]);
        $this->on("deleting", [$this, "onDeleting"]);

        $this->rewired = true;
        return $this;
    }
348320
public function delete($force = false) {
        Event::trigger('record_before_delete', $this);
        $model = get_called_class();
        $pk = $this->getPkField();
        $id = $this->$pk;
        if (isset($id)) {
            $where[ $pk ] = $id;
            $delete_time = "delete_time";
            if (property_exists($model, $delete_time)) {
                if (!$force) {
                    $this->$delete_time = time();
                    $this->update();
                    return;
                }
            }
            DB::delete($this->getTable(), null)->where($pk, $id)->excuse();
        }
        //删除缓存
        /* @var $db_cache DBCache */
        $db_cache = Ioc::get(DBCache::class);
        $db_cache->recordWhereCacheDel($model, $this->cacheKeys(), $this->_db_data);
        $db_cache->recordCacheDel($model, $id);
    }
703977
public function delete($productId, $force = null)
    {
        $options = (object)[];
        $options->qs = [ "force" => ($force ? "true" : "false") ];

        return $this->client->delete("/products/" . rawurlencode($productId), null, $options);
    }
1003591
public function persist($force = false) {
        global $DB;

        if (!$this->dirty && !$force) {
            return $this;
        }

        if ($this->id) {
            $record = $this->to_record();
            $DB->update_record('tool_usertours_steps', $record);
        } else {
            $this->calculate_sortorder();
            $record = $this->to_record();
            unset($record->id);
            $this->id = $DB->insert_record('tool_usertours_steps', $record);
            $this->get_tour()->reset_step_sortorder();
        }

        $this->reload();

        // Notify of a change to the step configuration.
        // This must be done separately to tour change notifications.
        cache::notify_step_change($this->get_tourid());

        // Notify the cache that a tour has changed.
        // Tours are only stored in the cache if there are steps.
        // If there step count has changed for some reason, this will change the potential cache results.
        cache::notify_tour_change();

        return $this;
    }
838250
public function server(bool $force = false)
    {
        // 过期时间

        $access_token = $this->cache->get('wechat_access_token_'.$this->app_id);

        if (!$access_token || true === $force) {
            // access_token 的有效期目前为2小时，需定时刷新，重复获取将导致上次获取的 access_token 失效
            // 过期或强制刷新
            $access_token = $this->getForce();
            $expire_time = $this->getExpireTime();
            $code = 200;
        } else {
            // 未过期
            $access_token = $this->cache();
            $expire_time = $this->getExpireTime();
            $code = 304;
        }

        $expire_data = date('Y-m-d H:i:s', time() + $expire_time);

        return compact('code', 'access_token', 'force', 'expire_time', 'expire_data');
    }