We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38417
    • 92 Posts
    If got a minor problem with logged in, logged out view on my site.
    My resources are all cached and the personalize snippet is called in the header. Login in and out is functioning flawlessly. Only the login and logout status doesn't show correctly when a page is called again. Changing the resources in uncached solved the problem, but I don't prefer this solution.

    So I have put this in the personalize snippet: $modx->cacheManager->refresh();
    and all is functioning as it should be. Is this a correct solution? After an update I have probably change it again, or is it possible to put this line in a future update?

    Ad.
    • Try calling the personalize snippet uncached instead
      [[!personalize]]
        Frogabog- MODX Websites in Portland Oregon
        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
        Having server issues? These guys have MODX Hosting perfected - SkyToaster
        • 38417
        • 92 Posts
        The snippet is called uncached!
        This is my snippet cal:
        [[!Personalize? &yesChunk=`header_for_members` &noChunk=`header_for_guests` &ph=`name` &landing=`12`]]
          • 39932
          • 483 Posts
          Refreshing the cache like that works well, however, you are refreshing the entire cache. Try replacing your $modx->cacheManager->refresh() with the following. It will reduce load times and speed the refresh. It will also not affect the entire site.

          if(!empty($modx->resource))
              $modx->cacheManager()->refresh(array(
                  'auto_publish' => array('contexts' => array($modx->context->key)),
                  'context_settings' => array('contexts' => array($modx->context->key)),
                  'resource' => array('contexts' => array($modx->context->key), 'ids'=> array($modx->resource->get('id'))),
               ));
          else
              $modx->cacheManager()->refresh();
          


          This will target the Resource (if we correctly have one, which we should). If we don't have one, it has a nice fallback. Additionally, it keeps in line with auto_publishing if this is used on your site. You may remove the first array ('auto_publish') if you are not using it.

          Note: This targets the Resource, under the assumption that the Resource was the issue. If this does not keep it fixed, I can add a line which targets the Snippet too. [ed. note: fuzzicallogic last edited this post 11 years, 8 months ago.]
            Website: Extended Dialog Development Blog: on Extended Dialog
            Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
            Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

            Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
            • 3749
            • 24,544 Posts
            @showa26: Are you previewing from the Manager when you test this? That will give you unnatural results. You need to test from another browser where you're not logged in to the Manager.

            @fuzzicallogic: All Personalize does is check if the user is logged in to the current context. If the snippet is called uncached, the cached version of the resource should still have the snippet tag in it and the snippet cache for that snippet should be empty, so I'm confused by the OP's results. I don't use Personalize, but I do have the same code running in various places on cached pages with no trouble.


            ------------------------------------------------------------------------------------------
            PLEASE, PLEASE specify the version of MODX you are using.
            MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 11 years, 8 months ago.]
              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
              • 39932
              • 483 Posts
              @BobRay:

              I absolutely know this, sir. I was just helping the above gentleman who applied his fix (he is calling it uncached), so that his fix would not bog down his site. This behavior boggles me too. BTW, good call on asking about Previewing from the Manager.

              @showa26
              Following BobRay's question: It may also produce incorrect results if previewing in the same browser instance. You should have a different browser instance entirely when previewing. Otherwise, Login or any other Snippet that checks for the current authenticated user will behave incorrectly. [ed. note: fuzzicallogic last edited this post 11 years, 8 months ago.]
                Website: Extended Dialog Development Blog: on Extended Dialog
                Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
                Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

                Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
                • 38417
                • 92 Posts
                Putting in the script had no effect at all, it resulted in pages not being opened.

                To preview the site I logout out of manager and use different browsers. Flushing all sessions, clearing cache manually, nothing seems to lead to a positive result. Logging out still shows the username, logging in with another user shows different users in different pages.

                Putting in my first script, by the way I found this on the forum, works but the pages open very very slow!
                [ed. note: showa26 last edited this post 11 years, 8 months ago.]
                  • 39932
                  • 483 Posts
                  ... it resulted in pages not being opened.

                  That's unusual. This may be because of event timing (some information is not available at specific times, like you may have a resource, but not an id). In that case, just the refresh will have to do. sad

                  Logging out still shows the username, logging in with another user shows different users in different pages.

                  This sounds like a caching issue then. You may have to call all of your snippets uncached... Certainly not desirable.
                    Website: Extended Dialog Development Blog: on Extended Dialog
                    Add-ons: AJAX Revolution, RO.IDEs Editor & Framework (in works) Utilities: Plugin Compatibility List
                    Tutorials: Create Cross-Context Resources, Cross-Context AJAX Login, Template-Based Actions, Remove Extensions from URLs

                    Failure is just another word for saying you didn't want to try. "It can't be done" means "I don't know how".
                    • 38417
                    • 92 Posts
                    Found it!

                    Searching the forum for a solution I found this thread: http://forums.modx.com/thread/78313/error-displaying-pages-until-cache-cleared-in-same-browser-solved Bob advised Frogabog to disabling plugins one by one.
                    I tried this and the first one bingo! I installed XHTML Beautify and that one gave me the trouble. I don't know how but maybe it is possible to warn others that this addon can create bugs.

                    Thank you for your help.

                    ps: I created a report in the add-on . [ed. note: showa26 last edited this post 11 years, 8 months ago.]
                      • 3749
                      • 24,544 Posts
                      I'm glad you got it sorted (and that it wasn't a problem with Personalize).

                      Thanks for reporting back. I'm sure people will find the info useful. smiley


                      ------------------------------------------------------------------------------------------
                      PLEASE, PLEASE specify the version of MODX you are using.
                      MODX info for everyone: http://bobsguides.com/modx.html
                        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