Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Configurations for Woocommerce when using Redis Cache #621

Closed
nikgoy opened this issue Sep 21, 2015 · 7 comments
Closed

Correct Configurations for Woocommerce when using Redis Cache #621

nikgoy opened this issue Sep 21, 2015 · 7 comments

Comments

@nikgoy
Copy link

nikgoy commented Sep 21, 2015

I am using EasyEngine single site with Woocommerce. So, we will have to use some additional config. I created a additional file called woo.conf and placed it in /var/www/mysite.com/config/nginx as this directory is automatically included. The settings are

if ( $cookie_woocommerce_items_in_cart = "1" ){
     set $skip_cache 1;
}

# Don't cache uris containing the following segments
if ($request_uri ~* "(/shop.*|/cart.*|/my-account.*|/checkout.*|/addons.*|/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
    set $skip_cache 1;
}   

location ~ \.php$ {
    set $rt_session "";

    if ($http_cookie ~* "wp_woocommerce_session_[^=]*=([^%]+)%7C") {
                    set $rt_session wp_woocommerce_session_$1;
        }   

    if ($skip_cache = 0 ) {
        more_clear_headers "Set-Cookie*";
        set $rt_session "";
    }

    fastcgi_cache_key "$scheme$request_method$host$request_uri$rt_session";

    try_files $uri =404;
    include fastcgi_params;
    fastcgi_pass php;

    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;

    fastcgi_cache WORDPRESS;
    fastcgi_cache_valid  60m;
}

I'm not sure about the location block. Though this seems to work fine, but essentially what should be the correct config settings here.

@rahul286
Copy link
Member

@NikhilGoyal Above seem to be based on my config posted here - https://gist.github.com/rahul286/dc64ae84c97868b862c4

I never got time to test config correctly. Correct config will:

  1. Cache store pages for non-logged in visitors, as long as they are "just looking"
  2. As soon as a visitor adds something in cart, that and all subsequent request should skip cache for that visitor
  3. But cache should work for other visitors at the same time, who haven't added first item in cart

An easy way to test above is to shutdown php/mysql after cache warmup and see if product page is served from cache.

Can you please confirm if above is working fine?

@nikgoy
Copy link
Author

nikgoy commented Sep 21, 2015

Ok, as soon as I stop php-fpm , I get 502 - Bad Gateway error.

Plus I wanted to know more about this part, as I am using redis cache

    fastcgi_cache_key "$scheme$request_method$host$request_uri$rt_session";

    try_files $uri =404;
    include fastcgi_params;
    fastcgi_pass php;

    fastcgi_cache_bypass $skip_cache;
    fastcgi_no_cache $skip_cache;

    fastcgi_cache WORDPRESS;
    fastcgi_cache_valid  60m;

Should I even have this part because after adding this.. the website has become quite slow. I am not even sure if the pages are being cached or not.

@cobbman
Copy link

cobbman commented Sep 21, 2015

I'm doing something very similar, but in my woo.conf file this is all I have, and it seems to work fine:

if ($request_uri ~* "/store.*|/cart.*|/my-account.*|/checkout.*|/addons.*") {
         set $skip_cache 1;
}

@irhumbled
Copy link

@BigWilliam The only problem with that setup is any dynamic part of the site (e.g. cart widget showing items in cart) will show a cached version. @rahul286 makes a good point earlier that once they have an item in their cart any pages looked at shouldn't be cached.

@alexkappel
Copy link

This seems to work best for us regarding a mini-cart which is served on every page:

#Best practice so far
if ($http_cookie ~* "cookie_woocommerce_items_in_cart"){
set $skip_cache 1;
}

#Shouldn’t be needed (Above is faster)
#if ( $cookie_woocommerce_items_in_cart = "1" ){
#set $skip_cache 1;
#}

@monecchi
Copy link

monecchi commented Sep 9, 2016

Hey there. I've been following a few EE tutorials about optimizing woocommerce. I've came across two different code blocks regarding the setup.

I was wondering what's the difference between the two code blocks mentioned below, and more important yet, which one should I use? At the moment of writing, my website uses WooCommerce v. 2.6.4.

I created my website with EE version 3.7 by firing up ee create example.com --wpfc command. The website is live (not production optimized) yet, but it loads fast.

I'm not sure though the caching is working properly because I get a 404 GET response from Yith Wishlist plugin (I think). For details please see the support topic I created on rtCommunity forum.

Those are the different code blocks I mentioned, both described on EasyEngine tutorials section

WooCommerce Window Shopping Caching Technique

    if ($http_cookie ~* "wc_session_cookie_[^=]*=([^%]+)%7C") {
                set $rt_session wc_session_cookie_$1;
        }

WooCommerce Window Shopping Caching Technique

    if ($http_cookie ~* "wp_woocommerce_session_[^=]*=([^%]+)%7C") {
                    set $rt_session wp_woocommerce_session_$1;
        }   

I've tried both code blocks, and although cache seems to be working, I'm still getting the 404 GET response error.

I'd really appreciate if anyone could guide me on making woocommerce with fastcagi cache a truly optimized experience for the shop users.

Thanks in advance.

@rahul286
Copy link
Member

We are cleaning up issue tracker and closing this issue because we won't be able to contribute to this discussion further.

Please use http://community.rtcamp.com/c/easyengine for future support questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants