Magento Cache Clean - Quick and Easy
 

Magento Cache Clean – Quick and Easy

Written by +Will Hanke on September 25th, 2014

I do a lot of testing, changing, modifying, etc in Magento. With the system doing all the caching, sometimes you make changes and you can’t seem to get them to show up right on the front end. Typically, that happens because you forgot to clean the cache, the sessions, or both. Deleting the files (especially on a busy site) can be somewhat slow and painful, eating up valuable development time.

Sure, you can just turn the caching off, do your stuff and turn it back on, but that requires you to remember those steps. I tend to forget, especially the turn-it-back-on-when-I’m-done part.

One of the best things I ever stumbled upon is some quick code that can be added to the end of the default index.php page which automatically clears the cache and guarantees that you’re looking at the latest and greatest version of the page.

Here’s the code. You should see Mage::run($mageRunCode, $mageRunType); at the end of your file. It goes right after that.
$app = Mage::app();
if ($app != null)
{
$cache = $app->getCache();
if ($cache != null)
{
$cache->clean();
}
}

I recommend you save a copy of the index.php file as index_clearcache.php or something like that. Then you’ll have it when you need it, just pull it up in the browser. I don’t recommend modifying the actual index.php page, as that may change with Magento upgrades.

Lastly, I recommend you add it to your robots.txt file as a file that should not be indexed, or you may run into a duplicate content penalty issue.

About 

Will Hanke is the Chief Search Marketing Strategist at Red Canoe Media, a top St. Louis Search Marketing & SEO firm. In addition to helping some of the city's most recognizable brands with their online marketing strategy, Will also is an Amazon bestselling author, speaker and teacher.

 

Leave a Comment





What's Your SEO Score?

Enter the URL of any landing page or blog article and see how optimized it is for one keyword or phrase.