1、缓存文件依赖
1 $cache = YII::$app->cache; 2 $dependency = new yiicachingFileDependency(['fileName'=>'hw.txt']); 3 $cache->add('file_key','hello world',3000,$dependency); 4 var_dump($cache->get('file_key'));
当hw.txt文件中的内容出现变化,则该缓存过期
2、表达式依赖:
1 $cache = YII::$app->cache; 2 $dependency = new yiicachingExpressionDependency(['expression'=>'YII::$app->request->get("name")']); 3 $cache->add('expression_key','hello world',3000,$dependency); 4 var_dump($cache->get('expression_key'));
当 ['expression'=>'YII::$app->request->get("name")'] 中获得的name的值发生了变化,则缓存过期
3、DB依赖
1 $cache=YII::$app->cache; 2 $dependency = new yiicachingDbDependency( 3 ['sql'=>'SELECT count(*) FROM yii.order'] 4 ); 5 $cache->add('db_key','hello_world',3000,$dependency); 6 var_dump($cache->get('db_key'));