Skip to content

Instantly share code, notes, and snippets.

@rahul286 rahul286/moved.md
Last active Jun 16, 2018

Embed
What would you like to do?
woo-commerce fastcgi-cache session-conflict solution (attempt)
@toddlahman

This comment has been minimized.

Copy link

commented Apr 20, 2014

In WooCommerce 2.1 wc_session_cookie_ has changed to wp_woocommerce_session_.

@rahul286

This comment has been minimized.

Copy link
Owner Author

commented Sep 21, 2014

@toddlahman thanks. Updated this gist.

@pjv

This comment has been minimized.

Copy link

commented Oct 31, 2014

hi rahul, thanks for this. a few things:

  1. you should update your post HERE and incorporate the new stuff from this gist - especially the correct wp_woocommerce_session cookie name; maybe two versions in that post for people who are still using woo < 2.1 and people who are up to date.
  2. in this gist your are no-caching /shop.*, in the rt-camp post referenced above you use /store.*. Are these specific to your own needs? I found no woo uri on my site that includes "shop" and i also found no need (so far) to exempt "store" from the cache.
  3. i am not currently using this piece, but can you explain the reason for skipping the cache if $cookie_woocommerce_items_in_cart = "1". Why only when there is 1 item? In the other tutorial you have != "0". What would you want to happen if there were two items in the cart? EDIT: never mind this - i'll leave it here in case it explains something to others who might have the same question, but that "1" is not a qty, it's a binary "true"; it's saying that there are items in the cart, not that there is 1 item in the cart.
@rahul286

This comment has been minimized.

Copy link
Owner Author

commented Oct 31, 2014

@pjv

  1. I will update post soon. On side-note, I am planning to turn my all articles into a github repo with Jekyll/hugo based site. I guess that is best way to keep it updated. Can you tell me if it sounds good idea to you?
  2. Our store is at /store. Anything else can be added. I should have added note about it.
  3. You got it right. It's a binary flag. :-)
@pjv

This comment has been minimized.

Copy link

commented Oct 31, 2014

this is a little OT, but i recently built my first jekyll site. I used it as an exercise to catch up on a lot of stuff that i have been reading about but had no practical experience with. So on top of jekyll i am using octopus 3.0 (still in alpha) and i built a whole node/gulp based build and deployment infrastructure. It took a lot of work and tweaking to get everything set up, but now that it is, i have a lot of flexibility and it is very, very easy to add new posts and edit old ones written in clean, simple markdown, test locally and deploy with a single command. in my research i found a lot of very cool static site generation systems and maybe i'll switch to a different one someday (if i do it will mainly be to move to an all-node workflow), but for now i am finding jekyll to suit my needs pretty well. If you want to host on github, using jekyll seems like a no-brainer.

having your site's source embedded in an easily modifiable git repo definitely seems like a good idea to me.

@pablopaul

This comment has been minimized.

Copy link

commented Aug 3, 2015

@rahul286 why do you prefer to check for the "wp_woocommerce_session_" cookie instead of "woocommerce_items_in_cart"? What benefits do you see?

@rahul286

This comment has been minimized.

Copy link
Owner Author

commented Mar 11, 2016

@pablopaul both serves different purpose. woocommerce_items_in_cart is used to decide weather to skip cache or not.

Once a visitor adds something to cart and you decide to skip cache for them, you basically create a different cached version of site for them in lines using wp_woocommerce_session_

        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";

This avoid session/cart collision.

@ecouto

This comment has been minimized.

Copy link

commented Apr 1, 2016

sorry, but where I have to put woo-nginx.conf ? /etc/nginx/ ???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.