We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18397
    • 3,250 Posts
    Is there any way to clear the site cache from within a snippet?

    This would be a great thing for those who use both caching AND the NewsPublisher snippet.
      • 25663 MODX Staff
      • 12,272 Posts
      The page the Newspublisher snippet resides on should not be cached. "Articles" it creates can be cached. At least I can’t think of any reason they can’t be.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 18397
        • 3,250 Posts
        I am talking about those of us whose menu and certain index pages are cached. Without the site cache being cleared they would not display the newly created page (even with the show in menu flag = 1).


        clear the site cache from within a snippet

        How can this be done?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Create a snippet that deletes the cache files from the assets/cache folder. The emptyCache() function from the manager/processors/cache_sync.class.processor.php file could be modified slightly to do the job; it even keeps track of how many and which files are deleted for making a report. Of special interest is the preg_match() line.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 25663 MODX Staff
            • 12,272 Posts
            Or include your menu snippet so it won’t be cached: [!snippetName!]
              Ryan Thrash, MODX Co-Founder
              Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
              • 18397
              • 3,250 Posts
              Quote from: rthrash at Sep 11, 2005, 01:06 PM

              Or include your menu snippet so it won’t be cached: [!snippetName!]

              Yes but that would also mean alot of other snippets that index the news folder would need to be uncached and that would drastically slow down the site (I tied it [I have a slow host])
                • 13577
                • 302 Posts
                Not that you’ve asked a bad question, but if your host is so slow that having snippets uncached makes wait time unbearable, you would probably be better off with a new host. With today’s technology, caching snippets shouldn’t make a serious difference unless you have thousands of them on a page or something.

                Just one mans opinion.
                  Standard Disclaimer
                  I could be totally wrong.
                  • 18397
                  • 3,250 Posts
                  Thanks for your imput Jared.

                  I think xWisdom figured out how to clear the cache for the newspublisher snippet:
                  http://modxcms.com/forums/index.php/topic,920.msg5912.html#msg5912

                  In regard to the caching uncaching speed differance, when a page with about 5 snippets is cached its total php time (mysql will be 0 because of full caching) is about 0.1-0.3 seconds. With caching disabled pages take up to 3-5 seconds generation time.


                  better off with a new host

                  Wish I could switch but I prepaid..........


                    • 13577
                    • 302 Posts
                    Quote from: Mark at Sep 12, 2005, 05:42 PM
                    ...In regard to the caching uncaching speed differance, when a page with about 5 snippets is cached its total php time (mysql will be 0 because of full caching) is about 0.1-0.3 seconds. With caching disabled pages take up to 3-5 seconds generation time.
                    Well yeah. Then I’d be caching too! Glad you found a solution.
                      Standard Disclaimer
                      I could be totally wrong.