We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21056
    • 327 Posts
    I’m trying to understand exactly how caching works, to try and speed up a site which is running slowly (2.1 RC3)

    Examining the cache files, it appears to be using the values from the individual element caches, so when would the _content data in the cache file (which has a nicely prepared copy of the whole page) be used?
      Author: ManagerManager plugin - customise your ModX manager interface

      Rckt - web development, Sheffield, UK
    • When the Resource is loaded from the cache file...
        • 21056
        • 327 Posts
        smiley

        I should explain in a bit more detail!

        I was having some caching problems, so to debug it I edited one of the cache files by adding a comment to the source of _content (in fact to some HTML which was inserted by a cached snippet).

        When I viewed on the site, it wasn’t showing up.

        So I added some comments to one of the element caches for a snippet further down the file, and this DID show up. So ModX is using the non-cached version of the whole page, but using the cached elements to assemble it. In the caching settings, everything is turned on.

        So I was wondering under what circumstances ModX would use _content, and what circumstances it will compile the page from the various cached elements?
          Author: ManagerManager plugin - customise your ModX manager interface

          Rckt - web development, Sheffield, UK
        • I will attempt to answer this simply, you’d have to buy my book when it comes out to get a better explanation, including a flow chart.

          When a Resource is called:

          The Template is loaded (probably from cache) and the Resource is parsed from top to bottom.

          On the event it finds a MODX Revolution Tag, it looks inside the Tag to see if there is another Tag.

          If there is, it repeats this process until the Parser no longer finds nested Tags.

          The last "child" Tag found in the Nested layers is processed first
          -- If it is called cached (without the !), it is loaded from the cache
          -- If it exists there
          -- And has not out lived its lifetime

          -- If it is called uncached, it is loaded and processed raw

          The Parser continues up the Nested layers of the the first Tag found in the main document, pulling from cached and uncached data sources until the Parent Tag has been processed.

          It Next continues through the Resource to the next Tag and repeats this process until the Template and Resource content are completely processed.

          The Parser does NOT load cached content first and then uncached as some have suggested.

          It works top to bottom, first in - first out.






            Get your copy of MODX Revolution Building the Web Your Way http://www.sanitypress.com/books/modx-revolution-building-the-web-your-way.html

            Check out my MODX || xPDO resources here: http://www.shawnwilkerson.com
            • 21056
            • 327 Posts
            Thanks wshawn for the comprehensive explanation - very interesting.

            My mental model of how it SHOULD work is that if caching is turned on, and a resource is ticked as Cacheable, and has a cache file wich contains _content, and has not expired, then the _content should be used. It should only go to the database copy of the resource if the latter two were false.

              Author: ManagerManager plugin - customise your ModX manager interface

              Rckt - web development, Sheffield, UK
              • 21056
              • 327 Posts
                Author: ManagerManager plugin - customise your ModX manager interface

                Rckt - web development, Sheffield, UK
              • Quote from: ncrossland at May 24, 2011, 07:42 AM

                is this related to https://github.com/modxcms/revolution/commit/a3c6d44387c00f39671169298c55592979462247 ?
                Yes—you were correct Nick. The _content and _processed flags were not properly being loaded from the Resource cache files and thus the Template and cacheable tags were being reprocessed unnecessarily. Thanks for bringing this to my attention.
                  • 21056
                  • 327 Posts
                  Thanks, glad firstly you were able to fix it, and secondly that I wasn’t going mad / being stupid.
                    Author: ManagerManager plugin - customise your ModX manager interface

                    Rckt - web development, Sheffield, UK