🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` /** * 数据缓存 * 配置文件:项目下的config/web.php * 下的 components 项 * */ //获取缓存组件 $cache=\Yii::$app->cache; //往缓存中写数据 $cache->add('key1','hello world'); //如果key已经存在,则add不会生效 $cache->add('key1','hello world11111'); //读缓存中的数据 $data=$cache->get('key1'); var_dump($data); echo '<br >'; //修改缓存中的数据 $cache->set('key1','hello world2'); $cache->set('key1','hello world4'); $cache->set('key2','hello world3'); //读缓存中的数据 $data=$cache->get('key1'); //$data=$cache->get('key2'); var_dump($data); echo '<br>'; //删除缓存中的数据 $cache->delete('key1'); //读缓存中的数据 //$data=$cache->get('key1'); //清空所有缓存 $cache->flush(); $data=$cache->get('key2'); var_dump($data); echo '<br>'; ```