tp5緩存使用

//引入
use think\Cache;


//使用
                $options = [
                    // 緩存類型爲File
                    'type' => 'File',
                    // 緩存有效期爲永久有效
                    'expire' => 0,
                    //緩存前綴
                    'prefix' => 'think',
                    // 指定緩存目錄
                    'path' => APP_PATH . 'runtime/cache/',
                ];
                Cache::connect($options);

                if (!Cache::has($this->lightId)) {
                    Cache::set($this->lightId, $this->lightId, 15);//設置緩存時間15秒
                    return $return;
                } else {
                    return getjson('0', '存在', '');
                }


//刪除

          $options = [
                                // 緩存類型爲File
                                'type' => 'File',
                                // 緩存有效期爲永久有效
                                'expire' => 0,
                                //緩存前綴
                                'prefix' => 'think',
                                // 指定緩存目錄
                                'path' => APP_PATH . 'runtime/cache/',
                            ];
                            Cache::connect($options);
                            Cache::rm($goodordern['lightId']);//刪除緩存可進行下一個動作

QQ:961052877

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章