// +---------------------------------------------------------------------- namespace app\controller; use app\BaseController; use think\facade\Cache; use app\services\system\DictionaryService; class Base extends BaseController{ public $data = ['code' => 1, 'data' => '', 'message' => '']; public function initialize(){ $this->cacheData($this->request); //缓存基础数据 } protected function cacheData($request) { $diction = Cache::get('diction'); if(!$diction){ $service = app()->make(DictionaryService::class); $data = $service->getDictionaryAll(); Cache::set('diction', $data); } } }