We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22656
    • 121 Posts
    So, suppose I have a modx revo site url as

    something.com/shoes/
    (friendly url translating to something.com/product.html?product=shoes)

    then on that page i have a snippet which grabs products based on property "product":
    [[mysnippet &product=`[[GETproduct]]` ]]


    where GETproduct is a snippet with
    return $_GET['product'];


    Now, as the product.html page is set to cached, how can I achieve different cached versions for varied product iterations based on the url?
    So that /hats/, /socks/, /gloves/ all get cached, whilst using a single page within modx revo manager, product.html in above example.

    Setting both snippets to uncached achieves the effect and pages render what they should, however there is no full cached version of each separate snippet, as there are database queries being performed each time page is rendered. I would like to avoid this and have fully cached versions of the same page, for each of the URLs above, but do not see how? Is this even possible?
      • 22303 MODX Staff
      • 10,725 Posts
      You can use the getCache Snippet to "wrap" each mysnippet call and configurably cache the results until the Resource cache is cleared, or for a custom period of time.
        • 22656
        • 121 Posts
        Wow, this is great - exactly what i needed! Your plugins are awesome dude.

        I've noticed one small issue -
        $modx->regClientStartupHTMLBlock(  $modx->getChunk('something', array('var1' => $var1)));

        doesnt fire on subsequent cached calls.
        I've solved it by moving this line into its own snippet, outside the getCache call.