Clear Magento cache

前端 未结 4 2048
清歌不尽
清歌不尽 2021-01-03 02:25

I am using Magento ver1.6.1. I need to clear Magento cache programmatically.

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

I used the above code b

相关标签:
4条回答
  • 2021-01-03 02:40

    try this

    Mage::app()->cleanCache();
    
    0 讨论(0)
  • 2021-01-03 02:41

    If you are using Magento Enterprise (I'm using 1.13), the above code in the aforementioned answers does not seem to be enough to flush the full page cache.

    It took me a while to figure out what was going on, but there are a few methods that fire as a result of events when using the web interface that would not be covered when using the code above. Of critical importance, is the cleanCache method of Enterprise_PageCache_Model_Observer.

    To fix, I added the following code after either Magento Guy or Oğuz Çelikdemir's code.

    Enterprise_PageCache_Model_Cache::getCacheInstance() ->clean(Enterprise_PageCache_Model_Processor::CACHE_TAG);

    Hope this saves someone some time!

    0 讨论(0)
  • 2021-01-03 02:47

    To solve your problem you can Write a bash script that clears cache and session data.

    Magento Cache Syrup - A simple bash script to clear magento cache, session, reports and temporary data the sys-admin way to make sure your magento website performs better.

    This script clears the cache and session data from Magento installation on a Linux (ubuntu) server to make sure that it resolves the blank white page Magento error caused by cache and session data and makes sure your Magento website run faster. Login to your server as root and create a file named magento_cache_syrup.sh and put in the following code.

    #!/bin/sh
    rm -rf /var/www/sl60/var/cache/*
    rm -rf /var/www/sl60/var/session/*
    rm -rf /var/www/sl60/var/report/*
    

    Make sure that you change the path in the above code and point it to your magento installation. For absolute beginners, simply replace “/var/www/sl60” with the path to your magento website directory.

    Once you have corrected the path you can simply run the above script by calling it from the terminal.

    This should clear all the data in cache, session, tmp and reports directories in your Magento installation. But the problem does not end here. We need to make sure that we do it every time before we reach the blank white page. To solve this, we will enable a cron job on the server that runs the bash script (magento-cache-syrup) every 12 hours.

    Create a cronjob to run the bash script every 12 hours

    0 讨论(0)
  • 2021-01-03 03:00

    This is what you're after:

      try {
        $allTypes = Mage::app()->useCache();
        foreach($allTypes as $type => $blah) {
          Mage::app()->getCacheInstance()->cleanType($type);
        }
      } catch (Exception $e) {
        // do something
        error_log($e->getMessage());
      }
    

    Here's how you would do it automatically:

    http://mikebywaters.wordpress.com/2011/12/09/automatically-refresh-magento-cache/

    0 讨论(0)
提交回复
热议问题