• Resolved amauryt

    (@amauryt)


    Hello,

    There is something I don’t really get about the litespeed cache ESI :
    I thought that if I enabled ESI, the cart would automatically been considered as an ESI block and so, pages will be served from cache even to people having something in their cart.
    But, when I do some testing, when I am on a cached page (x-lsadc-cache: hit), if I put something in the cart and go to another cached page (or the same), the page is no more served from the cache (x-lsadc-cache: miss).

    Could you tell me if it’s something normal and if so how could I achieve serving pages from the cache even if something is in the cart, with the cart as an ESI block ?

    my test site is :
    https://f420-ad300e5de1b3.wptiger.fr/

Viewing 15 replies - 1 through 15 (of 15 total)
  • Hi,

    If you’re using WooCommerce, you should see the “Privately Cache Cart” setting under the “WooCommerce” tab on LSCache settings. Switch this setting to “ON” and you’ll see your shopping cart be served from the private cache.

    Thread Starter amauryt

    (@amauryt)

    Hello @tenkstars

    Thanks for the answer but perhaps I haven’t been enough clear.
    Yes I am using woocommerce and the option Privately Cache Cart is already on.

    But, as explained above, when all is working fine when nothing is in the cart (x-lsadc-cache: hit) but if I add something to the cart, the pages that normally are served from cached, aren’t anymore (x-lsadc-cache: miss).

    If I visit my site with something in the cart, the first time it’s miss and the second time it’s hit. So here i can deduce that the private cache is working.

    But what I don’t get is that I thought that with ESI activated, the pages should be served from the public cache even if something is in the cart.

    Thanks again for the help.

    BR

    P.S when you say “you’ll see your shopping cart be served from the private cache” how can i see it is served from public or private cache

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    this feature may requires theme to be compatible with it , as you can imagine , different theme can have different way to handle the cart

    you can enable debug log , and looking for something like this in HTML source code

    
    <!-- lscwp STOREFRONT_CART_HEADER -->		<ul id="site-header-cart" class="site-header-cart menu">
    			<li class="">
    							<a href="https://xxx/cart/" title="View your shopping cart">
    								<span class="woocommerce-Price-amount amount">41,00<span class="woocommerce-Price-currencySymbol">&euro;</span></span> <span class="count">2 items</span>
    			</a>
    					</li>
    			<li>
    				<div class="widget woocommerce widget_shopping_cart"><div class="widget_shopping_cart_content"></div></div>			</li>
    		</ul>
    			<!-- Block generated by LiteSpeed Cache 3.6 on 2021-04-27 23:21:29 --><!-- lscwp STOREFRONT_CART_HEADER esi end --></div></div>
    	</header>

    `

    I tested with storefront theme , if I open some pages, like category page , then add some product into cart , then I refresh on the category page again , I still get cache hit , with cart content updated

    Best regards,

    • This reply was modified 3 years, 7 months ago by qtwrk.
    Thread Starter amauryt

    (@amauryt)

    Hello @qtwrk

    Thanks for the reply !

    Unfortunately, the only reference to litespeed I can see on the source code after enabling the debug log, it is at the end of the page :

    <!-- Page generated by LiteSpeed Cache 3.6.4 on 2021-04-28 01:34:12 -->
    <!-- X-LiteSpeed-Cache-Control: public,max-age=604800 -->
    <!-- X-LiteSpeed-Tag: 5b2_HTTP.200,5b2_WC_T.52,5b2_tax,5b2_URL.2fb983b276904005244fb9aa62d83e29,5b2_T.52,5b2_ -->

    I let the debug log enable if you’d like to check on my test site what could be wrong :
    https://f420-ad300e5de1b3.wptiger.fr/

    And so, if my theme is not compatible, how can I make it compatible ?

    Thanks again for the help !

    Best regards

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    this thing is little tricker

    you need to have both public cache with and without cart vary generated first

    e.g. you will first need to generate a public cache with vary “cart is not empty” and then this public cache will be used for all “cart not empty” cases

    then you will have 2 public caches for same pages , one gives to users with empty cart , one gives to users with item in cart

    Best regards,

    Thread Starter amauryt

    (@amauryt)

    Hello @qtwrk

    I do not follow you on this :/

    How can I do what you say : generate 2 differents public cache ?

    And otherwise isn’t it a way to add something on my theme for the plugin to identify where is the cart ? (btw the cart is ajax)

    Thanks again,

    Best regards

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    when user has an empty cart , and this user visits page -> it generates public cache with vary “empty cart”

    when user has something in cart , and this user visits page -> it generates public cache with vary “not empty cart”

    despite they are both public cache , but they may have different content and generation time due to vary

    you follow me on this part ?

    so when user A with item in cart , visits the pages , first time it will give miss and this action will generate public cache with cart vary

    then the second user, user B , with some item in cart, visits the pages that has been already visited by user A , will give cache hit , with item in cart

    Best regards,

    • This reply was modified 3 years, 7 months ago by qtwrk.
    Thread Starter amauryt

    (@amauryt)

    Hi,

    How can I crawl my site with different “vary” ? What means this term regarding of your plugin ?

    And additional question, is there a way to identify if a request is coming from the public or the private cache, because I think I have another problem on my site: with a TTL of 1 week for public cache it seem that I am not served anymore from cache after a night… (i am not logged and nothing on my cart)

    Best regards

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    unfortunately the crawler is unable to crawl “varied page”

    for your second question , please check this guide

    Best regards,

    Thread Starter amauryt

    (@amauryt)

    Hello @qtwrk

    Thanks for the reply.

    Regarding the cart not considered as an ESI block, You said earlier :

    this feature may requires theme to be compatible with it

    Can’t I do something in the theme itself to have the cart compatible ?

    If ESI is off, customers with or without something in the cart are served from public cache (x-lsadc-cache: hit), and the cart is working.
    But if I activate ESI, customers with something in the cart are no more being served from public cache (x-lsadc-cache: miss) whereas the pages are cached without something in the cart.

    Thanks again for the help !

    Best Regards

    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    since you are using ajax, yo don’t need to bother with that part

    if I activate ESI, customers with something in the cart are no more being served from public cache (x-lsadc-cache: miss)

    this is what I have been trying to explain from the beginning

    you will have 2 sets of public cache , one with cart vary , one without it

    in simpler words , all users with empty cart , will see “public cache A” , and all users with item in cart , will see “public cache B”

    e.g.

    user A , empty cart -> visit page -> cache timestamp 00:00

    user B , empty cart -> visit page -> cache timestamp 00:00 , same cache as user A

    user C , empty cart -> visit page -> cache timestamp 00:00 , same cache as user A

    then , user A add something in cart

    user A , with item in cart -> visit page -> cache timestamp 00:10

    at this moment , user A has triggered and generated page with cart vary , so , when user B , add item in cart

    user B , item in cart -> will see the page with timestamp 00:10 that is generated by user A with item in cart

    by now , there are 2 sets of public caches , one , with cart empty , generated at 00:00 , and this set will be given to users with empty cart

    another one , with item in cart , generated at 00:10 , and this set will be given to the users with item in carts

    Thread Starter amauryt

    (@amauryt)

    Hello @qtwrk,

    Let me try to sum up.

    If I have an ajax cart, I do not have to care if litespeed is compatible or not with the theme cart as it will always be? So it is normal that I don’t see near my cart html what you mentionned above :
    <!-- Block generated by LiteSpeed Cache 3.6 on 2021-04-27 23:21:29 --><!-- lscwp STOREFRONT_CART_HEADER esi end -->

    If that’s a yes, it is normal to have the behaviour you mentionned above : the need to have 2 vary depending of the cart state ? (because I see this behaviour only if ESI is on. If it’s off, independently of the cart empty or not, user is served from the same cache, so why it has to be different with ESI on as the cart is ajax ?)

    If that’s a yes, and it’s the way litespeed work, needing 2 cache depending of the cart content, how can I enable some vary like you said ? Where can I set that in the plugin ?

    Thanks a lot again for your time and help,

    Best regards

    • This reply was modified 3 years, 7 months ago by amauryt.
    Plugin Support qtwrk

    (@qtwrk)

    Hi,

    yes , since you are using ajax cart.

    yes , it’s normal you see that behavior with ESI , because it takes it same way for ajax and non-ajax cart

    well, you can’t , the plugin will automatically handle it , it’s hard coded

    Best regards,

    Thread Starter amauryt

    (@amauryt)

    Hello @qtwrk,

    Thank you for you answers, it’s clear now.

    Just too bad that the crawler can’t crawl those vary :), maybe on a later update :).

    Thanks again,

    BR

    Hi,
    I think we have the same issue.
    Please read this in Litespeed Cache Slack Channel #wpcache
    https://golitespeed.slack.com/archives/C3RJHNBTQ/p1617444393117600

    Right now I use a temporary hack to solve this.
    wp-content/plugins/litespeed-cache/thirdparty/woocommerce.cls.php
    Around row 187 comment //$vary[ ‘woo_cart’ ] = 1;

    /**
     * Keep vary on if cart is not empty
     *
     * @since  1.7.2
     * @access public
     */
    public function vary_maintain( $vary )
    {
    	if ( $this->vary_needed() ) {
    		do_action( 'litespeed_debug', '(thirdparty/woocommerce.cls.php) API: 3rd woo added vary due to cart not empty' );
    		//$vary[ 'woo_cart' ] = 1; // Do not set Cookie 
    	}
    
    	return $vary;
    }
    
Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘ESI and cart’ is closed to new replies.