We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37625
    • 38 Posts
    Hi all,

    Modx version is 2.1.5-pl (traditional)

    I'm having a strange issue with caching.

    That's how things are set up:

    My templates have just this simple snippet call: [[!getTemplate]]

    "getTemplate" snippet simply returns a chunk with the same name of itself plus "_default" or "_mobile" depending on the user agent (example: Template is called "Home" and chunk "Home_default" is returned)

    In the "Home_default" chunk I have this: [[$header]] [[$content]] [[$footer]]

    There is an uncached snippet call in the "header" chunk, [[!getCurrentDate]], that should return the date of today.

    The problem is that once the page gets cached, the snippet return value gets cached as well and the date remains the same until the cache is cleared again.

    I have other projects set up like that and they work as intended.

    Thanks in advance
    Alessandro
    • If you have a placeholder you can use to identify the unique templates being cached, use this in the tag calls, e.g.
      [[!getTemplate? &userAgent=`[[!+userAgent]]`]]
      [[!getCurrentDate? &userAgent=`[[!+userAgent]]`]]

      Otherwise, MODX will cache the output of those non-cacheable tags along with the Resource and reuse it when reprocessing the non-cacheable tags when it encounters the exact same tag signature. Just make sure that your non-cacheable tags are unique within a single Resource, or the output from the first one to be processed will be used for the rest encountered on the same Resource.
        • 37625
        • 38 Posts
        Hi opengeek,

        thanks for answering.

        Maybe I didn't make myself clear enough, my bad.

        Chunk switching (desktop/mobile) works fine using the method above (I'm using it on various projects with no issues).

        My problem is that an uncached snippet (getCurrentDate) value gets cached in "header" chunk section in core/cache/resource/web/resources/1.cache.php:

         '[[$header]]' => '<!DOCTYPE html>
        ....
        ....
        ....
        <script>
        language = \'it\';
        current_date = new Date(2013,1,6);
        </script>
        </head>
        <body>


        In the header chunk I have:

        current_date = [[!getCurrentDate]];


        I have the same setup in other projects and in core/cache/resource/web/resources/1.cache.php I have:

         '[[$header]]' => '<!DOCTYPE html>
        ....
        ....
        ....
        <script>
        language = \'it\';
        current_date = [[!getCurrentDate]];
        </script>
        </head>
        <body>


        I hope I made myself clear.

        thanks