CacheController.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: NODELOG
  5. * Date: 2016/11/8
  6. * Time: 下午10:36
  7. */
  8. namespace backend\controllers;
  9. use yii\filters\VerbFilter;
  10. use yii\web\Controller;
  11. use Yii;
  12. class CacheController extends Controller
  13. {
  14. public function behaviors()
  15. {
  16. return [
  17. 'verbs' => [
  18. 'class' => VerbFilter::className(),
  19. 'actions' => [
  20. 'flush-cache' => ['post'],
  21. 'flush-cache-key' => ['post']
  22. ],
  23. ],
  24. ];
  25. }
  26. public function actionIndex()
  27. {
  28. return $this->render('index');
  29. }
  30. public function actionFlushCache()
  31. {
  32. Yii::$app->cache->flush();
  33. Yii::$app->session->setFlash('success', '操作成功');
  34. return $this->redirect(Yii::$app->request->getReferrer());
  35. }
  36. public function actionFlushCacheKey()
  37. {
  38. $key = Yii::$app->request->post('key');
  39. if (Yii::$app->getCache()->delete($key)) {
  40. Yii::$app->session->setFlash('success', '操作成功');
  41. };
  42. return $this->redirect(['index']);
  43. }
  44. }