YII缓存操作
//文件依赖 $dependency = new \yii\caching\FileDependency(['filename'=>'hw.txt'])}; $cache->add("file_key",'hello world',3000,$dependency);//$dependency决定了当缓存文件发生修改时也会失效
//表达式的依赖 $dependency = new \yii\caching\ExpressionDependency( ['expression'=>'\Yii::$app->request->get("name")'] ); $cache->add("expression_key","hello world",3000,$dependency); //当name的值发生变化时也会失效
//DB依赖 $dependency = new \yii\caching\DbDependency( ['sql'=>'SELECT COUNT(*) FROM yii.order'] ); $cache->add('db_key','hello world',$dependency); //当sql查询出来的结果发生变化时也会失效
$cache->flush()//清掉所有缓存
$cache->add();//会判断当前键cache是否存在,如果存在就不会添加