We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37059
    • 368 Posts
    We have created an intranet application with MODx. It works well enough, but it doesn't run very fast. I'm working on profiling now to determine the slowdown areas, but I think I already know one of the big ones - and I have no idea what to do about it.

    The application users have different company associations and permission levels, which are associated and calculated by custom logic. (Logic that's too complicated to outline here, but it doesn't relate directly to the question.) To facilitate using this info one the frontend, for forms, content, etc., we have a plugin that goes through it and sets it as placeholders.

    Now, all of this information is different for each user in the system, and some can change based on what the user selects during his session. (For example, the user can switch the "active branch" and have it persist through the session.) So, to ensure that the information is up-to-date, we have set the plugin to run onWebPageInit. This means that a whole raft of custom logic is running every time a page loads; hence my suspicion that this plugin is responsible for much of the sluggishness on the interface.

    Now that I think about it, active branch is the only piece of placeholder info that could change during the user session, and it is stored in a cookie. So putting it in a placeholder would take up very little power, if we could only find a way to "cache" the other custom placeholders - the ones that only change per user. (Among these are the placeholders set by the MODX Profile snippet, which we're running from the plugin to make all the user fields available to the interface.)

    So my question is, can anyone suggest a good way to "cache" these user-related placeholders - to store them per session, per user, so that we don't have to re-run the plugin every time a page loads?

    Any suggestions would be greatly appreciated.
      Jason
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      What about User Settings? Like System Settings and Context Settings, they are accessed via [[++setting]] tags rather than placeholders.
        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
        • 3749
        • 24,544 Posts
        Can you calculate them in a plugin attached to OnUserFormSave and save them as User Settings? Creating new Settings can be really slow, so you definitely don't want to do it on page loads if you can avoid it.

        If you need them to be per-session, they could still be User Settings calculated in OnWebLogin or they could be $_SESSION variables. I think $_SESSION variables would be a little faster.
          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
          • 37059
          • 368 Posts
          I like the $_SESSION variables idea. Storing data that could change per session in user settings seems a bit counter-intuitive.
            Jason
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            Ah, of course. I missed the part about it being dynamic. Definitely $_SESSION is the way to go then. You can use fastField to quickly fetch SESSION values, by the way.
              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
              • 22303 MODX Staff
              • 10,725 Posts
              You could also use getCache (or your own similar logic) and cache the results per user, in the resource cache, settings cache, or it's own custom partition. You just need to provide a unique cacheElementKey to accomplish that in the getCache Snippet.
                • 37059
                • 368 Posts
                @sottwell Thanks for the heads-up on fastField. I am always hearing about handy plugins I never knew of before.

                @opengeek getCache has already helped to speed up this particular site, used to optimize Wayfinder. But how would I use it with a plugin?
                  Jason
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  FastField is not a plugin. It's an actual replacement for the MODx parser. As of Revo 2.2.7 the ability to specify a custom parser in System Settings was added, and as far as I know fastField is the first one. So it doesn't have much of a performance hit if any, it simply extends the original parser to add another MODx tag [[#...]].
                    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