We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    I've observed (although not very scientifically) that the behavior of uncached snippets called from cacheable resources has changed from version to version. In the past I have called certain snippets uncached when needed, but have not worried or thought about the 'Cacheable' setting on the calling resource - it is set to cacheable by default, and my code has worked the way I want it to in this scenario. But then when I upgrade MODX, the behavior changes and output that shouldn't be getting cached starts to get cached.

    Most recently, I upgraded from 2.2.6 to 2.2.8 last week, and a custom login page stopped working properly. This was a resource that had been left with the default "cacheable" setting, but had two uncached snippets called in it. The snippets began intermittently not firing, and I think it has to do with cache issues. I looked at the resource itself this morning, and set the "cacheable" setting to false, and now the snippets seem to be properly firing every time.

    So: is the official rule that if you want uncached snippet output, you have to both call the snippet uncached and set the calling resource to uncacheable? If so, has this always been the rule, or when did it become the rule?

      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That should not be happening. A cached resource with uncached snippets should behave as expected: the resource is processed and cached except for the uncached snippet tags, which are processed after the page is loaded from cache. If this is not happening, then something else is going on.
        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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        For example, two otherwise identical cached resources with simple Wayfinder calls, one cached and one uncached, have this difference in their cache files:
            '_content' => '<html>
        <head>
        <title>MODX Revolution - Home</title>
        <base href="http://localhost/revo228/" />
        </head>
        <body>
        <ul><li class="first active"><a href="http://localhost/revo228/" title="Home" >Home</a></li>
        <li class="last"><a href="index.php?id=2" title="Testing" >Testing</a></li>
        </ul>
        </body>
        </html>',
        

            '_content' => '<html>
        <head>
        <title>MODX Revolution - Testing</title>
        <base href="http://localhost/revo228/" />
        </head>
        <body>
        [[!Wayfinder? &startId=`0`]]
        </body>
        </html>',
        


          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
          • 14883 ☆ A M B ☆
          • 450 Posts
          I'm going to have to do a little more research on this. What you have said makes total sense and fits with what my understanding had been of how uncached snippets should work. I've found a few other problems related to the situation that triggered this post, so maybe I was cause-jumping. Or solution-jumping. Or something like that.
            • 32699 ☆ A M B ☆
            • 427 Posts
            I discussed this in my book. I went as far as to go into the cache, grab the contents of a resource from the cache and showed the difference of what actually happens when the cache is in effect.

            I also monitor changes for the classes here: http://www.shawnwilkerson.com/modx-revolution/2013/04/11/compare-modx-revolution-objects/

            Sottwell, is correct. You are not experiencing intended behavior.

            Try hard deleting the cache: hit Clear cache in the Manger and delete everything in the /core/cache folder. I would also check the error logs (both in the Manager and in the Server software) and see if any of your snippets are causing an issue.
              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
              • 3749
              • 24,544 Posts
              Are the snippet tags in a chunk, by any chance? That's the only think I can think of that would cause them not to fire. If they're in the template or page content, even if things go wrong, you might see the wrong output or result, but they should still act as if they fired.
                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
                • 14883 ☆ A M B ☆
                • 450 Posts
                Quote from: BobRay at Jun 10, 2013, 05:40 PM
                Are the snippet tags in a chunk, by any chance? That's the only think I can think of that would cause them not to fire. If they're in the template or page content, even if things go wrong, you might see the wrong output or result, but they should still act as if they fired.

                I think this is the issue. I've found another scenario on my site where the caching behavior seems to have changed with the 2.2.8 upgrade. My SimpleSearch search results page. My search results markup looks like this:
                <h2>Results</h2> 
                [[!SimpleSearch?&tpl=`myTpl`]]
                <h2>Search Again</h2>
                <p>[[!SimpleSearchForm]]</p>


                But this is in a chunk, which is called cached, and is inserted into another chunk above it that is itself output from a cached snippet. The whole thing is terribly convoluted and I'm working on changing it - however, this deep-down nested/buried uncached call to the SimpleSearch snippet used to work, even in this convoluted context, but no longer works after the 2.2.8 upgrade.

                Setting the resource itself to uncached once again fixes the problem - and a search results resource probably should be set to uncached anyway; it only makes sense. But I want to keep gathering data on this, because it does seem that some more specific variation of the following statement is true:

                Uncached tags called from inside of cached chunks used to behave in a truly uncached manner, but they no longer do in the latest version(s) of MODX.
                  • 3749
                  • 24,544 Posts
                  The only way to really understand what's happening is to look at the files in the core/cache folder. You can see which tags are still there and which have been replaced.

                  I wonder if there's a MODX cache unit test around somewhere. If not, there should be.
                    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
                    • 22303 MODX Staff
                    • 10,725 Posts
                    It should definitely still work in 2.2.8. There is only one commit I can find that would affect this behavior between these two versions in any way...

                    https://github.com/modxcms/revolution/commit/fd8e7ce3a6b421fc95c6e3d94720bd8501f85fc5

                    If you revert that change (remove the two added lines), does this fix the behavior you are seeing?

                    lines to remove:
                                // convert $output to string if there were any processing
                                $output = (string)$output;
                    [ed. note: opengeek last edited this post 13 years, 3 months ago.]