Browse Source

console command to flush cache

tags/2.0.0-alpha
Alexander Makarov 12 years ago
parent
commit
137d472838
  1. 1
      framework/console/Application.php
  2. 49
      framework/console/controllers/CacheController.php
  3. 3
      todo.md

1
framework/console/Application.php

@ -127,6 +127,7 @@ class Application extends \yii\base\Application
'help' => 'yii\console\controllers\HelpController',
'migrate' => 'yii\console\controllers\MigrateController',
'app' => 'yii\console\controllers\CreateController',
'cache' => 'yii\console\controllers\CacheController',
);
}

49
framework/console/controllers/CacheController.php

@ -0,0 +1,49 @@
<?php
/**
* CacheController class file.
*
* @link http://www.yiiframework.com/
* @copyright Copyright &copy; 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\console\controllers;
use yii\console\Controller;
use yii\console\Exception;
use yii\caching\Cache;
/**
* This command allows you to flush cache.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0
*/
class CacheController extends Controller
{
public function actionIndex()
{
$this->forward('help/index', array('-args' => array('cache/flush')));
}
/**
* Flushes cache.
* @param string $component Name of the cache application component to use.
*
* @throws \yii\console\Exception
*/
public function actionFlush($component = 'cache')
{
/** @var $cache Cache */
$cache = \Yii::$app->getComponent($component);
if(!$cache || !$cache instanceof Cache) {
throw new Exception('Application component "'.$component.'" is not defined or not a cache.');
}
if(!$cache->flush()) {
throw new Exception('Unable to flush cache.');
}
echo "\nDone.\n";
}
}

3
todo.md

@ -13,8 +13,7 @@
* ProfileTarget (TBD after web is in place): should consider using javascript and make it into a toolbar
* unit tests
- caching
* a console command to clear cached data
* unit tests
* backend-specific unit tests
- validators
* FileValidator: depends on CUploadedFile
* CaptchaValidator: depends on CaptchaAction

Loading…
Cancel
Save