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

你可能感兴趣的:(thinkphp)