Nick Jones

a magento developer at Meanbee (@nickj89) and uk magento expert based in Bath

Magento How-to: Prime Your Cache

Once development is done you reach that all important milestone.. you switch caching on. Yeah, it’s a bit of an anticlimax really.

Caching only works when the cache is primed. It can take time for your visitors to reach every nook and cranny of your site, so why not automate it?

Login to your server and run the following

wget http://www.yourmagentostore.com -r --delete-after -nd --reject png,jpg,jpeg,gif

Specifying -r will make wget recursively download the contents of your site, –delete-after will ensure that the files you download are not kept on your hard drive, -nd will result in no directories being created and –reject, with the arguments png,jpg,jpeg,gif will not download any image files.

3 Responses to Magento How-to: Prime Your Cache

  1. Benxamin says:

    Excellent. I'm adding to my Coda clips collection!

  2. Pingback: Acadiana Websites - How To Prime Your Magento Cache

  3. Nikola says:

    Awesome! I now run this script as a daily cron in a multi-site setup where each store has a different URL:
    <?php
    /**
    * Magento
    * Execute a recursive wget for each of the stores in order to prime the Magento cache. Should be run daily.
    */

    require '../app/Mage.php';

    // Only for urls
    // Don't remove this
    $_SERVER['SCRIPT_NAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_NAME']);
    $_SERVER['SCRIPT_FILENAME'] = str_replace(basename(__FILE__), 'index.php', $_SERVER['SCRIPT_FILENAME']);

    Mage::app('admin')->setUseSessionInUrl(false);

    $websites = Mage::app()->getWebsites();
    foreach($websites as $site) {
    $stores = $site->getStores();
    $cnt = 0;
    foreach($stores as $store) {
    if($store->getCode() != 'default') {
    $_host = parse_url($store->getUrl(), PHP_URL_HOST);
    echo $_host . '…';
    exec('/opt/csw/bin/wget http://&#039; . $_host . ' –recursive –delete-after –no-directories –reject=png,jpg,jpeg,gif,js,ico,pdf,pl,hex,zip,txt,bin,css 1>/dev/null 2>/dev/null &');
    echo 'OK' . "
    ";
    }
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">