We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33968
    • 863 Posts
    I have a (Revo) project underway where the site relies heavily on custom data tables, with a small number of MODx resources simply providing views into various data queries.
    I have a custom url plugin which allows these views to be represented with friendly urls rather than url params. This requires an uncached snippet on the receiving page to ensure the correct data is retrieved.

    Any snippet working with that data on the ’view’ page (eg. to iterate over related objects) performs perfectly well uncached.
    But I want really snappy performance! When I try to call it cached, everything just disappears.

    It occurred to me that I need to build in some kind of custom caching functionality to allow me to cache the data.

    I’ve been reading up on the docs but am a little unsure as to how to proceed with this. Can anyone tip me in the right direction?
      • 22303 MODX Staff
      • 10,725 Posts
      Just wrap the snippet calls in getCache and the individual calls will by cached by unique properties and REQUEST parameters automatically along with the Resource (and according to the Resource cache configuration, e.g. ...

      [[!getCache? &tElement=`MySnippet` &propertyForMySnippet=`foo` &anotherPropertyForMySnippet=`bar`]]


      You can also override the cache configuration for getCache to, for instance, cache those unique requests for 20 minutes you would do:

      [[!getCache? &tElement=`MySnippet` &propertyForMySnippet=`foo` &anotherPropertyForMySnippet=`bar` &cacheExpires=`1200`]]
        • 33968
        • 863 Posts
        That’s brilliant, I hadn’t even realised there was a snippet for that. I’m glad I didn’t find out after trying to code something up from scratch!

        Thanks Jason smiley