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 built a rather large intranet site using MODx 2.2.8. On this site are certain pages that can only be viewed by certain groups. Obviously, we don't want these pages showing up in the navigation for users who will get an unauthorized error if they click. Wayfinder generates the navigation correctly for the logged-in user, but only when called uncached. And as it turns out, Wayfinder is among the most expensive snippets in system resources. Preliminary testing indicates that an uncached Wayfinder call adds at least two seconds to every page load on our site. As we continue to add more resources, this problem will only get worse. But if we cache Wayfinder to preserve resources, the same menu shows up no matter which group is logged in.

    So far I have come up with one possible solution, which in my opinion is a kludge. It is to call a different instance of Wayfinder for each user group using a conditional. If I'm thinking correctly, these Wayfinder calls could then be cached safely, as each one would be cached on its own. The implementation would look something like this:

    <nav>
    [[+modx.user.id:ismemberof=`group1`:then=`
    [[Wayfinder? startId=`0`]]
    `]]
    
    [[+modx.user.id:ismemberof=`group2`:then=`
    [[Wayfinder? startId=`0`]]
    `]]
    </nav>
    


    Like I said, it's a kludge - and I'm not a hundred per cent sure it would work.

    Even though Google has not yielded a solution to this problem with caching and permissions, I cannot imagine that I am anywhere near the first developer to deal with it. So, who out there has found a good solution, or even has some idea of what might work better? I can't wait to hear from you.

      Jason
      • 34018 ☆ A M B ☆
      • 100 Posts
      Why don't you try using the 'getResources' extra?
        ----
        Daniel Melo
        • 37059
        • 368 Posts
        Thanks for your reply, but what would be the benefit? Cached is cached, whether using getResources or Wayfinder. System resource load might be a little better, but implementation would be more difficult without really addressing the problem of permissions vs. performance.
          Jason
          • 34084 ☆ A M B ☆
          • 756 Posts
          I ran into some similar issues on several larger resource sites, thus I created mxExtendedMenu which you can also use a cacheElementKey parameter to change between your two groups. This in effect caches both groups based on the cacheElementKey as different entries and avoids the costly conditional modifier. Examples are provided in the snippet, sorry I haven't loaded much onto RTFM, but its flexible.

          Cheers
            Evo Revo // Ubuntu, CentOS, Win // Apache 2x, Lighttp (Lighty)
            Visit CharlesMx.com for latest news and status updates.
            • 37059
            • 368 Posts
            Quote from: charless at Nov 13, 2013, 03:42 PM
            I ran into some similar issues on several larger resource sites, thus I created mxExtendedMenu which you can also use a cacheElementKey parameter to change between your two groups. This in effect caches both groups based on the cacheElementKey as different entries and avoids the costly conditional modifier. Examples are provided in the snippet, sorry I haven't loaded much onto RTFM, but its flexible.

            Cheers

            Thanks! That sounds like exactly what I need. I'll see if I can figure out from the snippet examples how to get it going. I will post back here with results when I have something to share.
              Jason
              • 38290
              • 712 Posts
              You can also wrap wayfinder in getCache
                jpdevries
                • 37059
                • 368 Posts
                Quote from: dinocorn at Nov 13, 2013, 04:07 PM
                You can also wrap wayfinder in getCache

                I thought about that, but I didn't know if it would allow me to make the cache conditional depending on the usertype logged in. Essentially I need to maintain separate cache for each group, as they might all be logged in at the same time. Do you know if getCache would fit the bill for that?
                  Jason
                  • 38290
                  • 712 Posts
                  Quote from: polrbear at Nov 13, 2013, 04:09 PM
                  Quote from: dinocorn at Nov 13, 2013, 04:07 PM
                  You can also wrap wayfinder in getCache

                  I thought about that, but I didn't know if it would allow me to make the cache conditional depending on the usertype logged in. Essentially I need to maintain separate cache for each group, as they might all be logged in at the same time. Do you know if getCache would fit the bill for that?

                  It will. See the cacheElementKey option.
                  http://devries.jp/blog/2013/03/23/cash-in-big-with-modx-cacheing/
                    jpdevries
                    • 37059
                    • 368 Posts
                    Okay, here's what the docs say about the cacheElementKey option:

                    A custom identifier for the output to be stored as in the cache. If not specified, the output is cached using a unique signature based on the Resource it is being executed on, the properties sent to the Element being processed, and any non-standard $_REQUEST parameters that were detected.

                    I assume what I need to do is make the cache signature unique per group that's logged in. Would I just pass it the name/id of the group, or what?
                      Jason
                      • 38290
                      • 712 Posts
                      Exactly! Think of cacheElementKey as the name of the file the contents will be cached in
                        jpdevries