We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 39961
    • 25 Posts
    Hi
    Is there a simple way to clear the cache of a specific resource every 24 hours using CronManager and an extended version of the script below. Help implementing this would be great, I am using a Yahoo Finance to convert currency on this page and it is getting throttled due to too many calls I think! http://www.morocsurf.com/prices.html << now cached until I can sort the issue.

    $modx->cacheManager->refresh();


    Thanks in advance (hopefully).
    Gareth

    This question has been answered by multiple community members. See the first response.

    • discuss.answer
      • 3749
      • 24,544 Posts
      It's possible, but it's much easier just to uncheck the cacheable checkbox for the resource if the page-load times are still acceptable.

      There's information on clearing the cache for specific resources here.
        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
        • 39961
        • 25 Posts
        Hi
        Thanks for that, I'll take a look.
        Page load time is over 30 seconds, so not really an option.
        Thanks
        Gareth
          • 39961
          • 25 Posts
          I have test run that and it seems to work. I have setup with CronManager so we'll see how it pans out.
          Thanks again.
          Gareth
            • 3749
            • 24,544 Posts
            You'll probably want to add a visit to the page after you clear its cache (say, with cURL) in your cron snippet. Otherwise, the next person to visit it is going to get the 30-second delay.

            BTW, if it's just one page and won't change, and you don't need to distribute your code, it will be faster and easier to just delete its cache file with unlink(), since it will always have the same name.
              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
            • discuss.answer
              • 39961
              • 25 Posts
              Yes probably a good idea! …I was kind of hoping that the reload wouldn't be as bad as the caching might stop the call(s) to Yahoo being throttled. Fingers crossed. Thanks Bob!
                • 38593
                • 129 Posts
                I had a similar issue where I was drawing product inventory data from a server in Europe for use on a website hosted in the US. Because inventory didn't change quickly, it could be safely cached with an occasional refresh, to avoid long build times caused by the huge physical distances between servers.

                I used the unlink() method BobRay described. I had an array of the resources that needed refreshing and then for each id would first unlink that resource's cache file and then fetch the webpage to rebuild a new cache file. Fired it up at 3am each day via cron. It worked like a charm.

                Later added a manual refresh when product was sold through the US website, but that's another tale for another day smiley

                  Pedalers Bicycle Tours my website forged with MODX
                  vandergraaf-M static website generator for MODX