Use this simple yiic console command to clear the application cache(s) and/or assets. You can supply multiple caches comma seperated to --cacheID
I will appreciate comments and suggestions on that as well as any hint how to make this better.
Requirements ¶
Yii 1.1 or above
File Permissions ¶
Make sure that the user who is executing this command has the permissions to delete the assets. This can be done by using the same user who created the assets, using sudo or by setting sticky flags on your assets folder.
Exceptions ¶
You can not use this command to clear the APC Cache as cli mode and apache mode use different environments for it.
Usage ¶
This extension comes with two php files.
The AbstractCommand class extents CConsoleCommand with a new getHelp method that collects and prints globaloptions and action options. It also adds printf() and verbose() to be used as output methods that behave like printf but autoadd PHP_EOL and honor the global option verbose.
The ClearcacheCommand class can be used to clear the cache(c) and assets of your application.
Update your config imports section
'import' => array(
'application.commands.*',
),
Example Clear Cache ¶
./protected/yiic clearcache cache
./protected/yiic clearcache cache --cacheID=apcCache
./protected/yiic clearcache cache --cacheID=fileCache,memCached
Help ¶
$ ./protected/yiic clearcache help
Info: Usage: ./protected/yiic clearcache <action>
Actions:
all [--cacheID=cache] [--assetPath=]
cache [--cacheID=cache]
assets [--assetPath=]
help
Global options:
[verbose=0]
PHP Code ¶
Available as zipped download.
apc
Does clearing APC from cli works for you? I always thought that one can't access cache for mod_php or cgi from cli.
I definitely will use assets clearing :-)
Good question
I am not using mod_php but I will setup this scenario and give feedback on that.
clearing assets
I forgot that one in the docs. You'll have to make sure that the user who is running the command and the one who created the assets are the same or use sticky flags on your assets directory. Otherwise you cannot delete the assets.
I'll update the docs as soon as I have tested the apc issue.
missing import
In ClearcacheCommand.php you should add:
Yii::import('application.commands.AbstractCommand');
at the top.
imports & apc
I updated the missing import but what's the use? I still need the imports in my config, otherwise my AbstractCommand is not found.
About the APC you're right, it does not work. There are a few hackarounds on that and I#ll will think about an solution in my console command.
Needs a tweak for PHP 5.2
The AbstractCommand printf file needs a tweak for PHP 5.2 (yes, yes, I know :-)
protected function printf() { // added as PHP 5.2 doesn't like passing directly to another function $args = func_get_args(); call_user_func_array('printf', $args); printf(PHP_EOL); }
PHP 5.2 and APC
Well, normally I don't care about PHP < 5.3 but as the actual version of Yii is for 5.2+ I added your fix to printf and for verbose as well.
I also added a warning if you try to flush CApcCache.
With these two updates I have uploaded a new zip
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.