We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    I’m looking for a little clarification... and caching is subtle...

    So, when you cache the output of a Snippet, does that mean that uncached calls to that Snippet return the same data on every page where it’s called?

    E.g.
    Page 1                                                          Page 2
    [[Cached Snippet]]      <--- Cached Snippet Output-----> [[Cached Snippet]]
    


    Or Like this?
    Page 1: [[Cached Snippet]] <---- Cached Snippet Output v1
    Page 2: [[Cached Snippet]] <---- Cached Snippet Output v2
    


    Will they both get the same info? Or is there a version of the cached Snippet that’s different for each page? And what if the Snippet calls are different? E.g. if startId=1 and startId=2, they’d have to have separate cache files, right?

    And if a page is cached, but the Snippet isn’t, then does it more or less have the net effect of simplifying the substitution used? E.g. the cached page will be served to the browser without hitting the database at all, but if you have an uncached Snippet on the page, then MOST of the page will be served from the cache (and not from the db), but the Snippet will be executed on rendering, right? Or does the page caching override the Snippet caching? I.e. if the page is cached, does it just take a snapshot of the Snippet output and stow it away in the cached version of the page? I’m pretty sure it doesn’t, but I wanted to clarify.

    Thanks!
      • 36416
      • 589 Posts
      Quote from: Everett at Jan 23, 2009, 06:46 PM

      Will they both get the same info? Or is there a version of the cached Snippet that’s different for each page?

      Cached snippet content will be embedded inside page cache, so the two calls will store same info into different pages only if snippet produces same output with identical parameters at the time of call.

      And if a page is cached, but the Snippet isn’t, then does it more or less have the net effect of simplifying the substitution used? E.g. the cached page will be served to the browser without hitting the database at all, but if you have an uncached Snippet on the page, then MOST of the page will be served from the cache (and not from the db), but the Snippet will be executed on rendering, right?

      Right.
        • 9207 ☆ A M B ☆
        • 2,475 Posts
        Thanks. I was pretty sure that’s how things would have to work, but sometimes I think too much and confuse myself.
          • 9207 ☆ A M B ☆
          • 2,475 Posts
          So one other clarification... is the "?" pop-up window for Page Cache inaccurate? It says something to the effect of "if you use Snippets, be sure to leave this box unchecked." Is this an warning that dates back to a time when caching the page would take snapshots of any Snippets on that page?
            • 36416
            • 589 Posts
            Quote from: Everett at Jan 27, 2009, 04:17 PM

            So one other clarification... is the "?" pop-up window for Page Cache inaccurate? It says something to the effect of "if you use Snippets, be sure to leave this box unchecked."

            This is horribly misleading...
              • 9207 ☆ A M B ☆
              • 2,475 Posts
              Ok, good. I’m not the only one who’s confused by that "informative" pop-up. Where should that concern be addressed? It’s not really a bug... and I think the guys are hard at work on Revolution so these little things probably are just distracting.
                • 3749
                • 24,544 Posts
                You can file it on Jira as an "improvement" rather than a bug.

                Actually, I think they like seeing stuff like that because it’s so easy to fix compared to, say, IE7 quirks. wink
                  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
                  • 9207 ☆ A M B ☆
                  • 2,475 Posts
                  Ok, I filed an improvement in Jira.

                  Just to be sure I understand this, the page caching stores data in a different place than Snippet caching, right? So both cached and un-cached Snippets will be inserted into the cached page when the page is requested and rendered. So cached pages and uncached pages both substitute the Snippets into the snippet tags... a Snippet’s settings affect whether that rendering is done via pulling a cached file or from reading the database and executing the code. Either way, the text that replaces the [[Snippet]] call is not stored within the cached page.

                  Right?
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Quote from: Everett at Jan 28, 2009, 08:09 PM

                    Just to be sure I understand this, the page caching stores data in a different place than Snippet caching, right? So both cached and un-cached Snippets will be inserted into the cached page when the page is requested and rendered. So cached pages and uncached pages both substitute the Snippets into the snippet tags... a Snippet’s settings affect whether that rendering is done via pulling a cached file or from reading the database and executing the code. Either way, the text that replaces the [[Snippet]] call is not stored within the cached page.

                    Right?
                    Not exactly, no.. it’s really much simpler: the cached page contains all the cacheable content, including the output of any snippets that were not called with noncacheable tags, i.e. [!Snippet!]. On uncached pages, all snippets will be evaluated; on cached pages, only uncached snippets will be evaluated after the cached content (which contains the [!Snippet!] calls) is loaded.
                      • 9207 ☆ A M B ☆
                      • 2,475 Posts
                      Ah, thanks for the clarification. So then... let’s imagine a Snippet that prints out the current time. If you create a cashed page (page 1) with this cached Snippet at 1:00, and let’s say an hour later you add a new page (page 2) and you call this Snippet cached (with the same parameters). Will Page 1 show 1:00 and Page 2 show 2:00 until the cache is cleared? Would it matter whether or not Page 2 was cached or not?