最新消息:欢迎光临!

magento自动更新缓存脚本

php findever 1836浏览 0评论

magento后台更新内容后,每次都需要手动去更新下缓存,很不方便,所以写了个脚本每30s检查需要更新的缓存,并自动更新:

<?php


/***********************
 * Auto Cache Refresh  to be run by cron or from command line 
 * By ifindever@gmail.com
 ***********************/

$mageapp  = '/var/www/html/magentocn/app/Mage.php';       // Mage app location

ini_set("display_errors", 0);
set_time_limit(0);
require_once $mageapp;
while(1){
	try{
		Mage::app('admin')->setUseSessionInUrl(false);
		Mage::getConfig()->init();

		$session = Mage::getSingleton('adminhtml/session');

		$invalidatedTypes = Mage::app()->getCacheInstance()->getInvalidatedTypes();

		foreach ($invalidatedTypes as $type) {
			$tag = $type->getTags();
			Mage::app()->getCacheInstance()->cleanType($tag);
			Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => $tag));
			echo Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT).'  [OK] '.$tag." Refresh Complete.\n";
		}

		echo Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT).'  [OK] '."Auto Refresh Cache Complete.\n";
	}catch(Exception $e){
		echo Mage::app()->getLocale()->date()->toString(Varien_Date::DATETIME_INTERNAL_FORMAT).'  [ER] '.$e->getMessage();
	}
	
	sleep(30);
}
 
?>

在linux系统中,用nohup php clearCache.php >> clearCache.log& 命令在后台运行即可,日志会输出到clearCache.log中

转载请注明:Findever » magento自动更新缓存脚本

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址