• Resolved seekthekingdom

    (@seekthekingdom)


    Hello, I am implementing the caching strategy for out site. Please help me understand if my design is correct and achievable.

    I would like to achieve the layout where my main page is public and doesn’t vary on any cookies. Then I have the public ESI block and public AJAX call which vary based on some cookie.

    1. I am using a plugin, which adds LiteSpeed Cache integration by defining the site-wide and page specific cookies. I would like to disable the site-wide cookie varies so that I can achieve the result as described above – for blog post and content pages I would serve a single public version of page. However I cannot achieve this by modifying the filter litespeed_vary_cookies inside my theme functions. Somehow LSCache still recognizes the cookie defined by the plugin and doesn’t want to serve cached, public version of page. Instead it caches the version for that particular cookie value.
      This happens only on some pages, e.g. for all blog posts it works prefectly. For some pages with content from the Gutenber editor it doesn’t.
      The .htaccess vary entry doesn’t include the cookies defined by the plugin that I am filtering out, so it seems to be well configured. Please help.
    2. For some pages I would also like to vary the whole page based on the cookie. In that case could my ESI block and the AJAX call be independent? So that for example the ESI blocks vary on cookie_a and the page varies on cookie_b and cookie_c independently. Is this possible?
      As mentioned above, it currently works on some pages, but I wanted to confirm the my understanding of the core concepts is accurate.

    Thanks for your help

    • This topic was modified 3 weeks, 4 days ago by seekthekingdom.
    • This topic was modified 3 weeks, 4 days ago by Yui.
Viewing 13 replies - 1 through 13 (of 13 total)
  • Thread Starter seekthekingdom

    (@seekthekingdom)

    I am adding the code that I use to modify the cookies:

    add_filter( 'litespeed_vary_cookies', 'reset_global_cookie_vary' );
    function reset_global_cookie_vary($cookies) {
    $excluded = array('cookie1', 'cookie2', 'cookie3');

    return array_filter( $cookies, fn( $cookie ) => ! in_array( $cookie,$excluded, true ) );
    }

    Thread Starter seekthekingdom

    (@seekthekingdom)

    Hey, I tested the design with a custom cookie and it seem to work like a charm 🙂 I really appreciate the thought process behind the caching system that you have built. Excellent work!

    Right now I will move on with using a different cookie than the one set by the plugin. If someone manually enters it in the browser it would be the edge case.

    To make the implementation more future-proof I would still like to ask for help in proper removing of the global vary cookies so that LSCache ignores them.

    Plugin Support qtwrk

    (@qtwrk)

    I’m sorry , I’m little confused now , what exactly is your question now ?

    and by the way , I think the cookie _lscache_vary is hardcoded and default recognized by server, so this one can not be changes from plugin side though.

    I think any other should be manipulatable

    Thread Starter seekthekingdom

    (@seekthekingdom)

    Hehe it is confusing to me as well 🙂

    I don’t mean the default _lscache_vary. Some cookies are added by the 3rd party plugin using the filter litespeed_vary_cookies. I am trying to remove them also by using that filter.

    The cookies are not in the .htaccess entry nor they are present in the LSC debug log. Yet when those cookies are in the browser LSCache doesn’t serve the cached page at all or creates a new variant. And this doesn’t happen on every page.

    My quesition is how to completely ignore cookies added by the 3rd party plugin?

    Would anything else trigger the public cache miss? No default vary, url is the same

    Plugin Support litetim

    (@litetim)

    @seekthekingdom I would try changing default priority for filter: add_filter( 'litespeed_vary_cookies', 'reset_global_cookie_vary', 9999 ); and run your code there: to allow only cookies you want

    • This reply was modified 3 weeks, 4 days ago by litetim.
    Thread Starter seekthekingdom

    (@seekthekingdom)

    Thank you, I am doing that, but without luck. As described previously, the config looks good, but doesn’t work as expected.

    Maybe there is something else going on with this 3rd party plugin, because all works very well with my custom cookie. I will now move on to making the patch and let you know afterwards.

    Plugin Support litetim

    (@litetim)

    @seekthekingdom
    I see. From what I understand: the vary cookie array is correct but LSC is not working as expected.
    Correct?

    Thread Starter seekthekingdom

    (@seekthekingdom)

    I am not sure whether this is LSC or some other code that forces mismatch in the cache key.

    The 3rd party plugin I am referring to is Curcy – the multi-currency WooCommerce solution.

    My context is that for content pages only the currency switcher block and a product slider fetched client side with AJAX need to know about currently selected currency. The rest of the page e.g. a blog post or content page does not need a separate variation based on a currency. So I want to make these pages public and only the parts – the currency switcher and product slider – aware of the currency.

    The Curcy plugin sets global vary cookies and also request specific cookies. I think it is because there was a misunderstanding in your docs about how to implement this. Because it doesn’t make sense when one understands that this is just about the cache key string. I have also had troubles with it in the past, but noticed that you have amended the docs lately.

    I want to reimplement the currency switcher with my own cookie logic. Let me come back to you when it is done so we could triage this.

    In the meantime I have also come across another potential defect. It is related to droping query params from the cache key.

    Context:
    I am doing a url crawl with the currency cookie set in header to warm the cache. Later when a visitor views that page url with param e.g. ?currency=USD the proper cookie is set via .htaccess. I excluded this query param from cache so that I don’t need to crawl another url.
    This works great, but only when I use litespeed_vary_no. In other case the first visit with query param is a miss, even though the main url is cached. After the first visit with excluded query param all next visits with any of excluded params are hits.

    Steps to reproduce:

    1. Exclude a query param in the admin settings
    2. Visit the page url without any query params
    3. Visit the same page url with excluded query param added to the url
    4. See that it is a miss
    5. Visit the page again with any of excluded query params
    6. See that it is a hit
    7. Redo the scenario with litespeed_vary_no added to the page request and see that it works for the first time.

    Expected result:
    It should be a hit every time when a main url is cached and the query param is excluded in settings

    Thread Starter seekthekingdom

    (@seekthekingdom)

    Hi, I have run multiple tests in different configurations using crawler and in neither of those was able to achieve to fully cached results.

    For pages and blog posts with no varies, always 100% hit. For product and shop pages which use vary cookie the only case where I was able to have hits is when I defined the global cookie.

    My conclusion is that I assumed the cache key system to be request specific so that I can define that for that page I want just one version and for this page I want vary based on cookie. At the moment you need to have multiple versions of everything in order for the site to be cached and served from the cloud.

    Please correct my if my understanding is wrong.

    Plugin Support qtwrk

    (@qtwrk)

    for query , you need to use drop query string option , not exclude

    for vary and crawler , if you have multiple varies on cookie , then you probably need to simulate the cookie on crawler as well

    Thread Starter seekthekingdom

    (@seekthekingdom)

    Yes, drop query string.

    Custom vary rules in .htaccess I will explore this more.

    Thank you, LSC is a great tool!

    Thread Starter seekthekingdom

    (@seekthekingdom)

    Hello, I was able to proceed with my desired setup.

    However I am currently having some problems with the LSC crawler not caching the ESI blocks when indexing pages. They do not get cached for user agents lscache_runner or lscache_walker and all works fine for others/default. Is this a behavior specific to my server config? Can this be configured on the WP side?

    Thanks

    Thread Starter seekthekingdom

    (@seekthekingdom)

    I have figured it out. Need a separate sitemap with ESI blocks

Viewing 13 replies - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.