如何清理Magento缓存?(How to clean Magento cache?)

编程入门 行业动态 更新时间:2024-10-24 20:16:21
如何清理Magento缓存?(How to clean Magento cache?)

我需要一个简单的脚本来刷新Magento缓存的每一个元素。 我正在运行1.3.2.3,无法升级。

I need a simple script that will refresh every single element of the Magento cache. I'm running 1.3.2.3 and can't upgrade.

最满意答案

用于刷新magento缓存的示例cron作业脚本:(该脚本在amartinez的 magento论坛中发布

通过cron作业运行

00  0 * * *   root /var/www/html/magento/cron_refresh_cache.php >> /var/log/cron_refresh_cache.log

php文件:

#!/usr/bin/php <?php /** * cron_refresh_cache.php * * @copyright copyright (c) 2009 toniyecla[at]gmail.com * @license http://opensource.org/licenses/osl-3.0.php open software license (OSL 3.0) */ ( !$_SERVER["HTTP_USER_AGENT"] ) or die ( "Nothing to do\n" ); // to run via local browser use ($_SERVER["SERVER_ADDR"] == $_SERVER["REMOTE_ADDR"]) require_once 'app/Mage.php'; umask( 0 ); Mage::app( "default" ); // if getting error change this line to Mage::app(Mage::app()->getStore()); $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 ); refresh_cache(); // call refresh function function refresh_cache() { $this -> notify( 'Refreshing cache' ); try { Mage :: getSingleton( 'catalog/url' ) -> refreshRewrites(); $this -> notify( 'Catalog Rewrites was refreshed successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getSingleton( 'catalog/index' ) -> rebuild(); $this -> notify( 'Catalog Index was rebuilt successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { $flag = Mage :: getModel( 'catalogindex/catalog_index_flag' ) -> loadSelf(); if ( $flag -> getState() == Mage_CatalogIndex_Model_Catalog_Index_Flag :: STATE_RUNNING ) { $kill = Mage :: getModel( 'catalogindex/catalog_index_kill_flag' ) -> loadSelf(); $kill -> setFlagData( $flag -> getFlagData() ) -> save(); } $flag -> setState( Mage_CatalogIndex_Model_Catalog_Index_Flag :: STATE_QUEUED ) -> save(); Mage :: getSingleton( 'catalogindex/indexer' ) -> plainReindex(); $this -> notify( 'Layered Navigation Indices was refreshed successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getModel( 'catalog/product_image' ) -> clearCache(); $this -> notify( 'Image cache was cleared successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getSingleton( 'catalogsearch/fulltext' ) -> rebuildIndex(); $this -> notify( 'Search Index was rebuilded successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getSingleton( 'cataloginventory/stock_status' ) -> rebuild(); $this -> notify( 'CatalogInventory Stock Status was rebuilded successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getResourceModel( 'catalog/category_flat' ) -> rebuild(); $this -> notify( 'Flat Catalog Category was rebuilt successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getResourceModel( 'catalog/product_flat_indexer' ) -> rebuild(); $this -> notify( 'Flat Catalog Product was rebuilt successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } } ?>

Example cron job script to refresh magento cache : ( the script was published in magento forum from amartinez )

Run via cron job

00  0 * * *   root /var/www/html/magento/cron_refresh_cache.php >> /var/log/cron_refresh_cache.log

The php file :

#!/usr/bin/php <?php /** * cron_refresh_cache.php * * @copyright copyright (c) 2009 toniyecla[at]gmail.com * @license http://opensource.org/licenses/osl-3.0.php open software license (OSL 3.0) */ ( !$_SERVER["HTTP_USER_AGENT"] ) or die ( "Nothing to do\n" ); // to run via local browser use ($_SERVER["SERVER_ADDR"] == $_SERVER["REMOTE_ADDR"]) require_once 'app/Mage.php'; umask( 0 ); Mage::app( "default" ); // if getting error change this line to Mage::app(Mage::app()->getStore()); $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 ); refresh_cache(); // call refresh function function refresh_cache() { $this -> notify( 'Refreshing cache' ); try { Mage :: getSingleton( 'catalog/url' ) -> refreshRewrites(); $this -> notify( 'Catalog Rewrites was refreshed successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getSingleton( 'catalog/index' ) -> rebuild(); $this -> notify( 'Catalog Index was rebuilt successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { $flag = Mage :: getModel( 'catalogindex/catalog_index_flag' ) -> loadSelf(); if ( $flag -> getState() == Mage_CatalogIndex_Model_Catalog_Index_Flag :: STATE_RUNNING ) { $kill = Mage :: getModel( 'catalogindex/catalog_index_kill_flag' ) -> loadSelf(); $kill -> setFlagData( $flag -> getFlagData() ) -> save(); } $flag -> setState( Mage_CatalogIndex_Model_Catalog_Index_Flag :: STATE_QUEUED ) -> save(); Mage :: getSingleton( 'catalogindex/indexer' ) -> plainReindex(); $this -> notify( 'Layered Navigation Indices was refreshed successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getModel( 'catalog/product_image' ) -> clearCache(); $this -> notify( 'Image cache was cleared successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getSingleton( 'catalogsearch/fulltext' ) -> rebuildIndex(); $this -> notify( 'Search Index was rebuilded successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getSingleton( 'cataloginventory/stock_status' ) -> rebuild(); $this -> notify( 'CatalogInventory Stock Status was rebuilded successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getResourceModel( 'catalog/category_flat' ) -> rebuild(); $this -> notify( 'Flat Catalog Category was rebuilt successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } try { Mage :: getResourceModel( 'catalog/product_flat_indexer' ) -> rebuild(); $this -> notify( 'Flat Catalog Product was rebuilt successfully', 'blank'); } catch ( Exception $e ) { $this -> notify( $e -> getMessage(), 'warning' ); } } ?>

更多推荐

本文发布于:2023-04-29 11:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336400.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   Magento   cache   clean

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!