doulanli6146 2011-03-28 14:06
浏览 49
已采纳

如何清理Magento缓存?

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.

  • 写回答

3条回答 默认 最新

  • doulou9927 2011-03-28 16:31
    关注

    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
    " ); // 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...
    ";
    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' );
                }
            }  
    
    
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样