[SOLVED] Clear Cache From Console

I’ve written a console application to generate initial RBAC roles, permissions, and assignments. The console application also allows permitting/revoking a permission for a given role.

I’m using DbManager as my authManager and AppCache as my caching mechanism.

'cache' => [ 

    'class' => 'yii\caching\ApcCache', 

 	'keyPrefix' => 'counsellor'



'authManager' => [

    'class' => 'common\components\rbac\DbManager',    

    'defaultRoles' => ['guest'], // Important - all roles inherit (accumulate) defaultRoles    

    'cache' => 'cache'


The issue I’m running into is I cannot invalidate the cache from the console; from the web is OK. For example, this is one of the methods that is called from a console action:

protected function _revoke($roleName, $permissionName)


	$authManager = Yii::$app->authManager;

	$role = $authManager->getRole($roleName);

	if (!$role) {

		throw new Exception(Yii::t('app', 'prefix:err_subject:noRole', array('roleName' => $roleName)));


	$permission = $authManager->getPermission($permissionName);

	$authManager->removeChild($role, $permission);



[size="2"]The cache is never cleared. print_r($authManager->cache); from the console outputs the following:[/size]

ApcCache Object (

    [keyPrefix] => counsellor

    [serializer] =>

    [_events]    => array()

[size=“2”]which leads me to believe the cache isn’t fully [/size]initialized[size=“2”] yet. Has anyone run into this? Is it a problem with my configuration file?[/size]

You cannot clear cache from console. I ended up writing a web controller to handle cache management and use the console to curl to the web controller. I can post some code if people are interested.

What about console command "yii cache/flush-all" and "yii cache/flush xxx yyy zzz" available in here http://www.yiiframework.com/doc-2.0/yii-console-controllers-cachecontroller.html ?

No luck. From what I’ve been reading, you cannot clear Apache (web) cache from CLI. Some people have reported success running [color=#222222]PHP-FPM. [/color]See here :

Looks like you are right.


which is used by \yii\caching\ApcCache::flushValues() https://github.com/yiisoft/yii2/blob/master/framework/caching/ApcCache.php#L132

which is called by \yii\caching\Cache::flush() https://github.com/yiisoft/yii2/blob/master/framework/caching/Cache.php#L317

and which is called here \yii\console\controllers\CacheController::actionFlush() https://github.com/yiisoft/yii2/blob/master/framework/console/controllers/CacheController.php#L96

may not work in CLI even with apc.ini set apc.enable_cli=1

Maybe you should create new issue at GitHub https://github.com/yiisoft/yii2/issues

I did a few weeks ago - https://github.com/yiisoft/yii2/issues/8647

I think the best solution here is to create a GUI interface to manage cache. Then, if needed, use CLI to call appropriate GUI actions.