What does “invalidated” cache mean in Magento?

后端 未结 3 433
北恋
北恋 2021-01-30 23:38

In the Magento admin under Cache Management, what does it mean when it shows a cache as invalidated? How does Magento know a cache is invalidated? In particular, I\'m wonderin

相关标签:
3条回答
  • 2021-01-31 00:07

    The @Magento Guy answer is correct, but I think this solution below can help you on refreshing just the invalidated caches on Magento.

    I use Bitnami Magento Stack, for me this solution below was the best I have found.

    I've tried to create a Mage_Shell_Class php file, but without success (invalid cache array were always empty when it runs, no matter what, and I really don't imagine why).

    I've created a php file 'sample.php':

    <?php
    
    require 'app/Mage.php';
    
    $invalid = Mage::app()->getCacheInstance()->getInvalidatedTypes();
    
    foreach($invalid as $i)
    {
        Mage::app()->getCacheInstance()->cleanType($i["id"]);
    }
    

    I've placed it on magento root folder, and to start it I use a cronjob that runs under root user.

    So, to create the cronjob on the root user:

    sudo crontab -u root -e
    

    And this was my command line to run it:

    * * * * * . /opt/bitnami/scripts/setenv.sh ; /opt/bitnami/php/bin/php /opt/bitnami/apps/magento/htdocs/sample.php >> /var/log/cron/cron.log 2>&1
    

    Some parts on this line are very particular to my problem:

    1. Since it just refreshes the invalidated caches I've decided to run it every minute.
    2. setenv.sh is a script that helps me to set the environment when dealing with this particular bitnami stack.
    3. To get the output of this script I used this last part ">> /var/log/cron/cron.log 2>&1" to output errors to a directory that I've created (/var/log/cron), and has given the correct permissions on it.

    Probably you need to change the cron line command, but I think this will help you.

    0 讨论(0)
  • 2021-01-31 00:09

    In Magento, whenever you make changes to products, static blocks, etc, it recognizes that the data in the database is no longer the same as what it has in the cache. Unfortunately, Magento doesn't realize what cache data is different, just that something is different.

    You will need to go into System > Cache Management and refresh the invalidated cache types.

    EDIT:

    Create a module (or use an existing module) that you can use to set up a cron job for refreshing the cache. Create a file: {namespace}/{modulename}/Model/Observer.php

    Inside that file:

    <?php
    class <namespace>_<modulename>_Model_Observer {
    
      public function refreshCache() {
        try {
          $allTypes = Mage::app()->useCache();
          foreach($allTypes as $type => $blah) {
            Mage::app()->getCacheInstance()->cleanType($type);
          }
        } catch (Exception $e) {
          // do something
          error_log($e->getMessage());
        }
      }
    
    }
    

    In your module's etc/config.xml:

    <config>
      ...
      <crontab>
        <jobs>
          <{modulename}_refresh_cache>
            <schedule><cron_expr>* * * * *</cron_expr></schedule>
            <run><model>{modulename}/observer::refreshCache</model></run>
          </{modulename}_refresh_cache>
        </jobs>
      </crontab>
      ...
    </config>
    

    Now as long as cron is configured correctly on your server, the cache will update automatically, as often as cron runs.

    0 讨论(0)
  • 2021-01-31 00:25

    2015: AOE Sheduler is able to clean the cache by cronjob. Change JOB

    "core_clean_cache"

    from 30 2 * * * (Daily 2:30) to 59 * * * * (Every 59 Minutes).

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