We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36613
    • 328 Posts
    I developed a site in MODX Revolution 2.2.2-pl ​​that updates the content every night with a php script. For each resource I have 5 images that are canceled recharged every night, very often happens that the texts and images remain mostly in the cache of modx and images in phpThumb cache.
    How do I clear all cache completely every night?
    If I empty manumalmente from the manager everything works but I try an automatic way that every night I empty the cache. On the net I found a scritp php cencellare the cache does not work.
    It 'a very serious problem because every day I have to open the manager clear the cache.
      • 33968
      • 863 Posts
      Try this:

      1) install cronmanager but only set the cronjob to run this once a night if you don't need it anywhere else
      2) have it call a snippet containing $modx->cacheManager->refresh();

      You can be more specific about which parts of the cache you want to update, as it might be overkill to clear the entire cache every night:
      http://rtfm.modx.com/display/revolution20/Caching#Caching-RefreshingtheMODXCache
        • 10208 ☆ A M B ☆
        • 1,780 Posts
        If you can attach the snippet RefreshCache to a cronjob as well, you could clear the entire cache every night and then run refreshCache immediately afterwards. Although Lucas is correct, if you can selectively clear only the cache file necessary, that would be best.

        Not sure how to activate RefreshCache in a cronjob. RefreshCache requires a click after viewing the resource to actually begin caching the site so you'd have to modify the snippet to automatically run itself I suspect.

        http://bobsguides.com/refreshcache-tutorial.html
          Frogabog- MODX Websites in Portland Oregon
          "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
          Having server issues? These guys have MODX Hosting perfected - SkyToaster
          • 33968
          • 863 Posts
          Quote from: frogabog at Jan 08, 2013, 02:03 PM
          Although Lucas is correct, if you can selectively clear only the cache file necessary, that would be best.
          That's what I was referring to in my last sentence, although I guess it wasn't very clear. The doc linked to shows how you can pass options to the cacheManager to only clear/refresh the parts you need to, rather than regenerating the whole thing.

          RefreshCache is a cool idea, and perfect to run from a cronjob. You could do that by including this in the file executed by the cronjob:
          // clear/refresh the cache
          $modx->cacheManager->refresh();
          
          // re-cache any uncached pages so the performance hit doesn't fall on site visitors
          $modx->runSnippet('RefreshCache');
          
            • 3749
            • 24,544 Posts
            I think this would refresh just the Resource cache, which should be enough:

            <?php
            /* get all the Contexts */
            $contexts = array();
            $query = $this->xpdo->newQuery('modContext');
            $query->select($this->xpdo->escape('key'));
            if ($query->prepare() && $query->stmt->execute()) {
                $contexts = $query->stmt->fetchAll(PDO::FETCH_COLUMN);
            }
            $results = array();
            
            $modx->cacheManager->refresh(array(
                'resource' => array('contexts' => array_diff($contexts, array('mgr'))),
            ), $results);
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 50923
              • 137 Posts
              I am using cronJob Manager, but lets say now is 22:00 how to makeit every day at 02:00am??
                <a href="www.play2web.com" title="izrada web sajtova">Izrada web sajtova</a>
                • 10208 ☆ A M B ☆
                • 1,780 Posts
                Quote from: miomir.dancevic at Aug 11, 2016, 03:49 PM
                I am using cronJob Manager, but lets say now is 22:00 how to makeit every day at 02:00am??

                Set the time to 02:00

                22:00 is 10pm, therefore 2am is 02:00.
                  Frogabog- MODX Websites in Portland Oregon
                  "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
                  Having server issues? These guys have MODX Hosting perfected - SkyToaster