Know Magento
Cleaning (Refreshing) Cache

Cleaning (Refreshing) Cache

Category: Cache – Posted Wednesday, June 10th, 2009.

The Magento Admin panel calls it refreshing (Refresh) the cache, while within the code it’s refered to as “cleaning” the cache.

If you want to Refresh your cache within the admin panel, simply go to System > Cache Management.  Drop the box labeled “All cache” down to the Refresh option and hit the Save cache setting button near the upper-right of the window.

If you want to clear your cache from the command line, SSH into your server and get into the base directory of your magento installation.  Type the following commands:

cd var/cache
rm -rf *

If you want to clean the cache from within your code (maybe within a cron or something), you’ll need to place the following PHP code within your script wherever you need the cache cleaned:

Mage::app()->cleanCache();

I’ve also seen the above written as:

Mage::app()->getCache()->clean();

However, the first way is preferred, since it allows for tags to be passed (outside the scope of this post) and also cleans the configuration cache.

If you’re creating a cron file that is outside of your Magento installation, you can use the following method so long as your cron script is running on the same server and has access to the Mage file system:

$mage_filename = '/[YOUR PATH TO MAGENTO]/app/Mage.php';
require_once $mage_filename;
umask(0);
Mage::run();
Mage::app()->cleanCache();

  • http://www.integritytextiles.co.uk/index Andy

    I’ve got myself in some kind of fix. I upgraded to 1.2.1.2 and Refreshed Cache Control. I am now getting

    “403 Permission Denied You do not have permission for this request /report/?id=990889617253&s=default”

    for all my magento links, including index.php/checkout/cart. What could the problem be? I tried setting permissions on some folders like /var/cache to 775 but still getting the error. My server doesn’t allow 777 and 666.

  • Jeff

    It could be an ownership problem, but without being able to get in there, I wouldn’t really know for certain. Besides, it sounds like you’re host may not be your best option. You would apply ownership like so:

    chown owner:group -R magento_directory

    Best of luck on your issue.

  • http://www.integritytextiles.co.uk/index Andy

    Thanks for the response Jeff.

    However. my magento is on root. What will be the chown command.

  • Angus Li

    Just a note – the following command line way only works for File System(default) cache adapter:
    cd var/cache
    rm -rf *

    If you use APC/eAccelerator/Mamcache for cache, need use other ways to clean from code.

  • http://www.designdisclosure.com Alistair Stead

    Hi,

    I’ve just released MageTool that provides command line tools to execute this task in a clean and simple way. You can also disable/enable cache or update configuration etc.

    http://www.designdisclosure.com/2010/10/magento-command-line-tools-magetool/

Buy Magento Books and learn more tips and guides

Copyright © 2011 KnowMagento.com. All rights reserved. Designed by . Privacy Policy