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

    I'm running MODX Revo 2.3.1.

    This is my snippet (I'm only using one parameter to keep it short) - Let's call it mySnippet:

    <?php
    
    if($_GET['param']){
        $bc_params = array(
            "titleField" => "menutitle"
        );
    } else {
        $bc_params = array(
            "titleField" => "pagetitle"
        );
    }
    
    $output .= $modx->runSnippet('Breadcrumbs', $bc_params);
    


    Whether I go to page.html or page.html?param=hello, !mySnippet is sometimes displaying menutitle, sometimes it's displaying pagetitle; there's no consistency, and it seems like it's getting cached.

    Does anyone know how to fix this?

    Thanks.
    jm
      Jean-Marc Buytaert (@jmbuytaert)

      MODX truly is the greatest thing that's ever happened to the Internet.
      • 3749
      • 24,544 Posts
      There's also the browser cache, and possibly a cache system on the server. I don't believe that the results of $modx->runSnippet() are ever cached, but I could be wrong.

      I assume that you're calling the snippet uncached. You can try making the page itself uncached to see if that has an effect.

      You can look at the raw cache files in the core/cache directory to see what MODX is, and isn't, caching. Make a note of the snippets' IDs first.

      You can cache-bust the file to keep the browser from caching it by adding a fake param on the end of the URL:

      $url .= '?param=hello&id=' . time();


      You can also do something like this in a plugin:

      header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
      header('Pragma: no-cache'); // HTTP 1.0.
      header('Expires: 0'); // Proxies.


      I'm not sure what the correct event would be -- maybe OnWebPagePrerender.
        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