[英]Flushing Magento cache
我有一个问题:当我尝试以编程方式刷新Magento缓存时,如下所示:
$types=array('config','layout','block_html','translate','collections','eav','config_api','config_api2');
foreach($types as $type) {
$c = Mage::app()->getCacheInstance()->cleanType($type);
Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => $type));
}
[ 来源 ]
我已阅读这篇文章关于Magento的缓存,它的冲洗,但我仍然失去了一些东西。
上面的方法应该与“刷新Magento缓存”按钮相同,但就我而言,它不是。 当我运行脚本时,我要保存一个新的控制器,但是在使用上述方法(以及许多其他我已经尝试过的方法)以编程方式进行缓存刷新后,该控制器不起作用。
但是,一旦我在脚本工作的中间从管理面板手动执行相同操作,它便开始正常工作。
任何想法? 如果我将脚本代码放到这里,有帮助吗?
提前致谢!
您的代码似乎只清除了块缓存,对于新的控制器/类,您将需要删除缓存文件夹,您可以像这样以编程方式进行操作
/**
* Remove cache folders:
*/
public function cleanFiles() {
try {
flush();
//cache
$dir = Mage::getBaseDir('cache');
$items = array_diff(scandir($dir), array('..', '.'));
foreach ($items as $item) {
$path = $dir . DIRECTORY_SEPARATOR . $item;
is_dir($path) ? $this->_rrmdir($path) : unlink($path);
}
} catch (Exception $e) {
die("[ERROR:" . $e->getMessage() . "]" . PHP_EOL);
}
}
/**
* Removes a directory and all elements contained
* @param string $dir directory to remove
*/
private function _rrmdir($dir) {
if (is_dir($dir)) {
$objects = array_diff(scandir($dir), array('..', '.'));
foreach ($objects as $object) {
$path = $dir . DIRECTORY_SEPARATOR . $object;
is_dir($path) ? $this->_rrmdir($path) : unlink($path);
}
reset($objects);
rmdir($dir);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.