Thứ Ba, 27 tháng 3, 2012

How to refresh magento cache using magento php code

create a file in the root folder of your magento for example refreshcache.php and write the below code to refresh your magento cache without logging to Admin panel
require_once 'app/Mage.php';

umask( 0 );

Mage :: app( "default" );

$ver = Mage :: getVersion();

$userModel = Mage :: getModel( 'admin/user' );

$userModel -> setUserId( 0 );

Mage :: getSingleton( 'admin/session' ) -> setUser( $userModel );

echo "Refreshing cache...\n";

Mage :: app() -> cleanCache();

$enable = array();

foreach ( Mage :: helper( 'core' ) -> getCacheTypes() as $type => $label ) {

$enable[$type] = 1;

}

Mage :: app() -> saveUseCache( $enable );

echo "Cache refreshed";