9 Replies Latest reply on Jan 28, 2013 7:48 AM by rush_pawan

    Caching at component level

    katrienj Level 1

      Hi, I read the following forum post: http://forums.adobe.com/message/4296426, like to get confirmation that this is how we need to implement our solution.

       

      This is the problem: we have a component that displays a link to Vimeo if the user is logged in, and a link to the login screen if not logged in. The page needs to be cached for performance reasons. Now the problem is that if the page is cached, the link displayed is also cached, so doesn't change depending hte user.

       

      We're using Adobe CQ authentication.

       

      Is there a way to make the content behind the link non-cached?

       

      Any feedback really appreciated.

        • 1. Re: Caching at component level
          rush_pawan Level 4

          Yes, you can refer metioned ticket as well

           

          OR

           

          You can try below too

           

          as per your problem statement you only have to display one of the two links "Vimeo" when user logged in or Login screen when user not logged in. So would suggest to create two selectors jsps let say "logged_in.jsp" and "anonymous.jsp" apart from your component jsp let say your component is "A" then you have "A.jsp"

           

          Now in A.jsp check the staus of user and make call to anyone of these jsp based on status by passing these names as selector because when selectors adds to request and it firms new url and in that way it will be not cached and server differenly.

           

          <sling:include resourcType="type of component" path="path to resource" addSelectors="logged_in"/>

           

          OR

           

          <sling:include resourcType="type of component" path="path to resource" addSelectors="anonymous"/>

           

          so above call it makes like

          http://<host>:<port>/content/yourproject/yourresourcearea/A.logged_in.html

          OR

          http://<host>:<port>/content/yourproject/yourresourcearea/A.anonymous.html

           

          Note: if addSelectors doesnt work then try replaceSelectors

          • 2. Re: Caching at component level
            katrienj Level 1

            Thanks for this reply. The vimeo link is dynamic (it's a parameter that is set by the author in the component) so any hints on how I can pass that on as well?

             

            EDIT, I guess the included jsp could read it from a property of the component.

            • 3. Re: Caching at component level
              rush_pawan Level 4

              Try generating selector dynamically it means if you have two different users like user1 and user2

               

              then call it as

               

              <sling:include resourcType="type of component" path="path to resource" addSelectors="logged_in.user1"/> and

              <sling:include resourcType="type of component" path="path to resource" addSelectors="logged_in.user2"/>

               

               

              Now doing this you are preparing separate url each time but because you dont have user1/user2 jsps in system so ultimately it will go to logged_in.jsp and there based on user information may be in request/session you have can be used to display.

               

              So the ultimate idea should be preparing differnt url request as possible but be in context of resource available in system.

               

              Also you can select what ever selector as you want for example instead of user1/user2 (of couse security reason) you can user something else.

               

              Try it out, i hope it will help you to resolve your issue. Let me know for more information.


              • 4. Re: Caching at component level
                Jörg Hoh Adobe Employee

                If you want to have caching, please consider the use of "permission sensitive caching", which is a feature of the Dispatcher. See http://helpx.adobe.com/cq/kb/PSCachingDelivery.html for more information.

                 

                My idea for implementation:

                 

                (video.html = vimeo link enabled/user authenticated, video.login.html = login/user not authenticated; you can change semantics based on your assumend usage.)

                 

                 

                • User requests video.html
                • Dispatcher handles this request with PSC enabled and requests the CQ5 if this page should be delivered out the cache.
                • If the user isn't authenticated yet, CQ5 sends a redirect to the video.login.html to the dispatcher; the dispatcher forwards this request to the browser then.
                • If the user is authenticated, CQ5 sends a statuscode 200 to the dispatcher; the dispatcher delivers then the file from the cache.

                 

                In these cases the HTML files are both cached on dispatcher, but every request to it also creates a request back to CQ5 for authentication and authorization. But we assume, that these are much lighter than a full request for a rendered HTML page (which includes these checks as well).

                 

                cheers,

                Jörg

                • 5. Re: Caching at component level
                  katrienj Level 1

                  Hi, thanks for your reply, that's indeed the idea I was exploring at the moment.

                  • 6. Re: Caching at component level
                    katrienj Level 1

                    Ok, so this is what I have:

                     

                    I have the component A of resourceType cq:component, and inside A I have two jsp's. One called anon.jsp (which renders the anonymous content) and one called loggedin.jsp (which renders the content that a logged in user can see).

                     

                    The component A can be included by an author on "resource" pages multiple times. Let's assume that test.html is one of such pages that has this component added.

                     

                    When I open test.anon.html, I get the anonymous content

                    When I open test.loggedin.html, I get the logged in content

                     

                    So all is fine and if I can use sensitive caching on the "loggedin" URLS, then that's great and all would be fixed.

                     

                    BUT ... how do I make sure that the selector "anon" or "loggedin" appears in my URL? Should I add some code in A.jsp? (The base jsp of the A component)? If I follow rush_pawan's sugggestion in the first reply to my original post, then that doesn't work.

                    • 7. Re: Caching at component level
                      rush_pawan Level 4

                      Hi,

                       

                      No, you need not require to pass selector as par of URL because you already adding selector while making the resource request as below

                       

                      <sling:include resourcType="type of component" path="path to resource" addSelectors="logged_in.user1"/>

                       

                      which automatically prepare url for that resource using passed selectors.

                       

                      Let me know if you need more information.

                       

                      Thanks,

                      Pawan

                      • 8. Re: Caching at component level
                        katrienj Level 1

                        Yes, that does work. But in that case, it also caches my page, which I don't want as explained in the first page.

                         

                        Do you think I am doing something wrong? You seem to think it shouldn't cache what A.jsp is doing?

                        • 9. Re: Caching at component level
                          rush_pawan Level 4

                          I hope you are passing different values for selector each time for different user, for example in below case

                          <sling:include resourcType="type of component" path="path to resource" addSelectors="logged_in.user1"/>

                           

                          the "user1" will be dynamic so that the request will be generated differently each time (as mentioned above).

                           

                          and if above doesn't seems to be working then place  response.setHeader("Dispatcher", "no-cache"); on both the pages which gets called while processing.