gpt4 book ai didi

php - 如何清理 Magento 缓存?

转载 作者:可可西里 更新时间:2023-11-01 00:07:03 24 4
gpt4 key购买 nike

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

最佳答案

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

通过定时任务运行

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' );
}
}


?>

关于php - 如何清理 Magento 缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5460165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com