karljohns0n / nginx-more

Development repository for nginx-more package
MIT License
120 stars 29 forks source link

Caching issues? #17

Closed erus00 closed 4 years ago

erus00 commented 4 years ago

Hi Karl,

Apparently I am experiencing a caching issue after importing a shop (woocommerce). The cart does not reflect what is added in it, it is showing "empty cart" for logged out users and working fine if logged in. I spent the day on this and just can't figure it out.

I used cachtool to flush the cache but this is not having any effect on the issue. php cachetool.phar opcache:reset --fcgi=/run/php-fpm/user1.sock

Questions: Is there a way to prevent the cart from being cached? What is the cache in place with nginx-more?

Thanks a lot

erus00 commented 4 years ago

Hi Karl,

in 'etc/nginx/conf.d/custom/fpm-wordpress-cache-users.conf" I added "/cart/ " to:

if ($request_uri ~* "/cart/|/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|sitemap(_index)?.xml") {
        set $skip_cache 1;
}

It seems to be working fine. Would you think this is the best way to do it or would you advise otherwise?

Thanks

karljohns0n commented 4 years ago

Hi,

You should be good with the following on WooCommerce:

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

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

I will update the wordpress cache templates on next update to support WooCommerce.

Thanks

erus00 commented 4 years ago

Hi Karl,

Thanks for that, I implemented it and it works perfectly.

Could you please let me know what is the best way to purge the cache by the terminal?

Visiting site_url/purge/ after putting my IP in /etc/nginx/conf.d/custom/admin-ips.conf is OK but I am looking for a more practical way that could also be used in a script.

Thank you very much.

karljohns0n commented 4 years ago

Could you please let me know what is the best way to purge the cache by the terminal?

Add an alias such as: alias purge-nginx-cache="rm -rf /var/lib/nginx/cache/fastcgi/*"

Visiting site_url/purge/ after putting my IP in /etc/nginx/conf.d/custom/admin-ips.conf is OK but I am looking for a more practical way that could also be used in a script.

This plugin works well to clear single page cache after editing: https://en-ca.wordpress.org/plugins/nginx-helper/

Karl

erus00 commented 4 years ago

Thanks Karl!

karljohns0n commented 4 years ago

See commit 8434453b2d6ca6ced7b780c55f472072e9e63c29.