根据主键获取对象

@param string|int $id
@param bool       $cache 是否使用缓存

@return $this;
434665
public static function get($id, $cache = true) {
        if (!$id) {
            return null;
        }
        $model = get_called_class();
        $db_cache = null;
        if ($cache) {
            /* @var $db_cache DBCache */
            $db_cache = Ioc::get(DBCache::class);
            $data = $db_cache->recordCache($model, $id);
            if ($data) {
                return $data;
            }
        }
        /* @var $model Record */
        $model = new $model;
        $pk = $model->getPkField();
        $where[ $pk ] = $id;
        $data = $model::find($where);
        if ($cache && $data) {
            $db_cache->recordCacheSave(get_called_class(), $id, $data->_db_data);
        }
        return $data;
    }
184658
protected function instantiateCache(Cache $cache = null)
    {
        if (is_null($this->cache) || ! is_null($cache)) {
            $this->cache = ! is_null($cache)
                ? $cache
                : new Cache($this->config);
        }

        return $this->cache;
    }
488689
public static function setDoctrineCache(DoctrineCacheProvider $cache)
    {
        self::$cacheImplementation = new DoctrineCache($cache);
        self::$hasBeenCleared      = false;
    }
848768
public function cache($id = null, $tags = [])
    {
        $this->_shouldCache = $id === false ? false : true;
        $this->_cacheId = is_string($id) ? $id : $this->_cacheId;
        $this->_cacheTags = $tags ? (array) $tags : $this->_cacheTags;

        return $this;
    }
263824
public static function buildCacheKey($id, $wkey = "Key")
    {
        $cache = Yii::$app->cache;
        if ($cache !== null) {
            $strClass = get_called_class();
            $key = $cache->buildKey([$strClass, ":{$wkey}:", $id]);
            Yii::debug('Build cache key: '.json_encode([$strClass, ":{$wkey}:", $id]).' = '.$key);
            return $key;
        }

        return null;
    }
726386
public function get($id, $default = null)
    {

        $cacheId = $this->cache->key([$this->prototype(), $id]);

        if ($this->cache->has($cacheId)) {
            return $this->cache->get($cacheId);
        }

        if ($model = $this->parent->get($id)) {
            $this->cache->put($cacheId, $model);
        }

        return $model ? $model : $default;
    }
757895
public function setId($id)
    {
       	if ($id !== null && is_numeric($id)) {
            $id = (int) $id;
        }
        $this->id = $id;

        return $this;
    }
36171
public function setId($id)
    {
        if (($content = $this->getContent()) instanceof FormInterface) {
            $content->setId($id);
        }

        return $this;
    }
1295203
public static function cache( int $id )
	{
		if( ! self::cacheIs($id) && $id === 0 )
		{
			$module = new ModuleCore();
			self::setCache(0, $module->setLoadedFromCache());
		}

		return self::defaultCache($id);
	}
615893
public function setTemplateId($id, $order = null) {
        if ($order === null) {
            // If no order is provided, append the template ID to the end of the list
            $this->template_ids[] = $id;
        } else {
            $this->template_ids[$order] = $id;
        }
        return $this;
    }
712803
protected function getHasCache($id)
    {
        return $this->useHasCache && array_key_exists($id, $this->hasCache)
            ? $this->hasCache[$id]
            : false;
    }
540237
public function recordCache($model, $id) {
        $cache_key = "record_" . $model . $id;
        $data = Cache::get($cache_key);
        if ($data) {
            Log::debug("命中缓存" . $model . " " . $id, 'cache');
            /* @var $record Record */
            $record = new $model;
            $record->fromDbData($data);
            return $record;
        }
        return null;
    }
638064
public function remove($id)
    {
        if (true === $result = @unlink($this->getCacheFile($id))) {
            $this->log('debug', sprintf('Cache data removed for id `%s`.', $id));
        }

        return $result;
    }
218055
public function setCache(Store $cache)
    {
        if (method_exists($cache, 'tags')) {
            $cache = $cache->tags($this->tag());
        }

        $this->cache = $cache;

        return $this;
    }
1339045
public static function buildCacheTag($id, $wkey = "Key")
    {
        $cache = Yii::$app->cache;
        if ($cache !== null) {
            $strClass = get_called_class();
            Yii::debug('Build cache tag: '.json_encode([$strClass, 'Tag', $id]));
            return [$cache->buildKey([$strClass, ":Tag:{$wkey}:", $id])];
        }

        return null;
    }
807478
protected static function getCache($id)
    {
        $type = static::getType();

        $id = (string)$id;

        static::initializeCache($type);

        $collection = self::$cache->{$type};

        if (!property_exists($collection, $id)) {
            return null;
        }

        $resource = $collection->{$id};

        return (clone $resource);
    }
4468
public function setContentId( $id )
    {
        $this->contentId    = empty( $id ) ? null : (int) $id;
        $this->_uriCache    = null;
        $this->_visible     = null;
        return $this;
    }