Our blog
Magento Bulk Cache / Index Update Script
If you are doing any kind of bulk updating etc then you also need to make sure that you rebuild all of the caches and indexes after your bulk updates otherwise things can go wrong.
I have just managed to get the following script to work including when flat catalog is enabled (thanks to Nick of Meanbee for the Mage::app() tip).
This script can be called from the browser (I would highly recommend some form of IP restriction or other security) or called from a cron job.
-
<?php
-
$magePath = '/path/to/Mage.php';
-
require_once $magePath;
-
//Varien_Profiler::enable();
-
//Mage::setIsDeveloperMode(true);
-
//ini_set('display_errors', 1);
-
-
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
-
-
echo '<h3>Cleaning overall Cache</h3>';
-
-
// clean overall cache
-
Mage::app()->cleanCache();
-
echo 'done';
-
-
echo '<h3>Cleaning Catalog Rewrites</h3>';
-
-
// clear 'refresh_catalog_rewrites':
-
//Mage::getSingleton('catalog/url')->refreshRewrites();
-
Mage::getModel('catalog/url')->refreshRewrites();
-
echo 'Catalog Rewrites was refreshed succesfuly<br>';
-
-
echo '<h3>Cleaning Image Cache</h3>';
-
-
// clear 'clear_images_cache':
-
Mage::getModel('catalog/product_image')->clearCache();
-
echo 'Image cache was cleared succesfuly<br>';
-
-
echo '<h3>Cleaning Layered Navigation</h3>';
-
-
// clear 'refresh_layered_navigation':
-
Mage::getSingleton('catalogindex/indexer')->plainReindex();
-
echo 'Layered Navigation Indices was refreshed succesfuly<br>';
-
-
echo '<h3>Clearing out Search Index</h3>';
-
-
Mage::getModel('catalogsearch/fulltext')->rebuildIndex();
-
echo 'Search index was rebuilt succesfully<br>';
-
-
echo '<h3>Rebuilding Flat Category</h3>';
-
Mage::getResourceSingleton('catalog/category_flat')->rebuild();
-
echo 'flat category was rebuilt successfully<br>';
-
-
echo '<h3>Rebuilding Flat Products</h3>';
-
Mage::getResourceSingleton('catalog/product_flat_indexer')->rebuild();
-
echo 'flat product was rebuilt successfully<br>';
-
More...
How to add custom fields to Magento checkout | KERNELHACK.com
Magento Stores Ecommerce Search Engine Optimization, Magento store ...
More Reading:
6 Comments
|
if you have any problems with this.. keep an eye on the core_flag table. If a process starts and doesn't stop properly you might get an orphaned flag in this table which will cause you problems.. |
|
[...] example check out this bulk cache update script I pulled [...] |
|
craig August 29th, 2010 |
I tried the above script "Index Update Script" PHP: Fatal error: require_once() [function.require]: Failed opening required '/path/to/Mage.php' (include_path='.:/usr/lib/php5') in /homepages/41/d293336770/htdocs/magento/cacherebuilder.php on line 8 |
|
you need to change /path/to/Mage.php to be the actual path to the Mage.php file (which is located in the App folder) |
|
How do you guys feel about the speed of Magento cache refreshing? I've worked on a Magento store with about 24k products, 50k product images and about 300 categories. At times the cache refreshing took about to 40min to complete. |
|
I haven't known it take that long, though with a script like this I would definitely suggest it is something that's done via cron in the middle of the night |
RSS Feed
admin
May 11th, 2009