<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] * * * * * # 1 緩存 >>緩存,使用外部存儲機制存儲框架的運行信息 >相對于配置,緩存可用跨請求使用。 >配置的修改與存儲只在當前請求中發揮作用,而緩存的修改與存儲則會影響到下個請求。 ## 1-1 緩存初始化 ### Cache::init() >>初始化配置中指定類型的緩存 ~~~ public static function init(array $options = []) { if (is_null(self::$handler)) { // 自動初始化緩存 if (!empty($options)) { self::connect($options); } elseif ('complex' == Config::get('cache.type')) { self::connect(Config::get('cache.default')); } else { self::connect(Config::get('cache')); } } } ~~~ ## 1-2 緩存存儲連接 ### Cache::connect() >>創建配置中指定類型的緩存存儲。 ~~~ public static function connect(array $options = [], $name = false) { $type = !empty($options['type']) ? $options['type'] : 'File'; if (false === $name) { $name = md5(serialize($options)); } if (true === $name || !isset(self::$instance[$name])) { $class = false !== strpos($type, '\\') ? $type : '\\think\\cache\\driver\\' . ucwords($type); // 記錄初始化信息 App::$debug && Log::record('[ CACHE ] INIT ' . $type, 'info'); if (true === $name) { return new $class($options); } else { self::$instance[$name] = new $class($options); } } self::$handler = self::$instance[$name]; return self::$handler; } ~~~ >>由上可知緩存機制默認使用File存儲,其多種存儲驅動實現在(\cache\driver\)目錄下 ## 1-3切換緩存存儲類型 >>可以用來切換緩存的存儲類型 ### Cache::store() ~~~ public static function store($name) { if ('complex' == Config::get('cache.type')) { self::connect(Config::get('cache.' . $name), strtolower($name)); } return self::$handler; } ~~~ # 2 緩存操作 >>緩存的操作包括,存儲數據到緩存存儲器中,讀取緩存存儲器中的數據 ### Cache::get() >>讀取緩存中數據 ~~~ public static function get($name, $default = false) { self::init(); self::$readTimes++; return self::$handler->get($name, $default); } ~~~ ### Cache::set() >>存儲數據到緩存 ~~~ public static function set($name, $value, $expire = null) { self::init(); self::$writeTimes++; return self::$handler->set($name, $value, $expire); } ~~~ ### Cache::has() >>檢查緩存數據 ~~~ public static function has($name) { self::init(); self::$readTimes++; return self::$handler->has($name); } ~~~ ### Cache::inc() >>緩存自增 ~~~ public static function inc($name, $step = 1) { self::init(); self::$writeTimes++; return self::$handler->inc($name, $step); } ~~~ ### Cache::dec() >>緩存自減 ~~~ public static function dec($name, $step = 1) { self::init(); self::$writeTimes++; return self::$handler->dec($name, $step); } ~~~ ### Cache::rm() >>刪除緩存 ~~~ public static function rm($name) { self::init(); self::$writeTimes++; return self::$handler->rm($name); } ~~~ ### Cache::clear() >>清空緩存 ~~~ public static function clear($tag = null) { self::init(); self::$writeTimes++; return self::$handler->clear($tag); } ~~~ ### Cache::tag() >>帶標簽緩存 ~~~ public static function tag($name, $keys = null, $overlay = false) { self::init(); return self::$handler->tag($name, $keys, $overlay); } ~~~ # 3 內置緩存驅動 >>tp5內置了多種緩存驅動實現不同形式的存儲方式。如File,Redis,Memacahce. >這里簡單分析File類緩存驅動 >其他類型緩存接口相似 ## 3-1 緩存驅動抽象類(Driver) ### $driver->getCacheKey() >> 獲取緩存標識 ~~~ protected function getCacheKey($name) { return $this->options['prefix'] . $name; } ~~~ ### $driver->pull() >>讀取緩存并刪除 ~~~ public function pull($name) { $result = $this->get($name, false); if ($result) { $this->rm($name); return $result; } else { return null; } } ~~~ ### $driver->tag() >>帶標簽緩存 ~~~ public function tag($name, $keys = null, $overlay = false) { if (is_null($keys)) { $this->tag = $name; } else { $key = 'tag_' . md5($name); if (is_string($keys)) { $keys = explode(',', $keys); } $keys = array_map([$this, 'getCacheKey'], $keys); if ($overlay) { $value = $keys; } else { $value = array_unique(array_merge($this->getTagItem($name), $keys)); } $this->set($key, implode(',', $value)); } return $this; } ~~~ ### $driver->setTagItem() >>設置緩存標簽 ~~~ protected function setTagItem($name) { if ($this->tag) { $key = 'tag_' . md5($this->tag); $this->tag = null; if ($this->has($key)) { $value = $this->get($key); $value .= ',' . $name; } else { $value = $name; } $this->set($key, $value); } } ~~~ ### $driver->getTagItem() >>獲取緩存標簽 ~~~ protected function getTagItem($tag) { $key = 'tag_' . md5($tag); $value = $this->get($key); if ($value) { return explode(',', $value); } else { return []; } } ~~~ ## 3-2 緩存驅動實現類(File) ### $file->__construct() >>文件存儲緩存構造函數 ### $file->init() >>文件緩存初始化 ### $file->getCacheKey() >>獲取變量的存儲文件名 ### $file->has() >>判斷緩存是否存在 ### $file->get() >> 讀取緩存 ### $file->set() >> 寫入緩存 ### $file->inc() >>自增緩存 ### $file->dec() >>自減緩存 ### $file->rm() >>刪除緩存 ### $file->clear() >>清空緩存 ### $file->unlink() >>文件刪除。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看