Bypass cache when add to cart ?

Tobias Honacker t.honacker at googlemail.com
Wed Dec 23 22:35:44 CET 2015


Hi Xavier,

maybe this snippet will help you

Cookie: https://github.com/lkarsten/libvmod-cookie
Query String: https://github.com/Dridi/libvmod-querystring

default.vcl:

import cookie;
import querystring;

sub vcl_recv:

if (req.url ~ "^/random/url") {
    cookie.parse(req.http.Cookie);
   cookie.filter_except("cookie_woocommerce");
    if ((cookie.isset("cookie_woocommerce")) {
      return(pass);
    } else {
      return(hash);
    }
} // to get the value out of the cookie -> cookie.get("woocommerce") !=
"false"

and something like this

 set req.url = querystring.sort(req.url);
 set req.url = querystring.filter(req.url, "query_string");
 ... do some magic

2015-12-23 21:05 GMT+01:00 Guillaume Quintard <
guillaume at varnish-software.com>:

>
> On Dec 23, 2015 20:51, "Xavier Cardil Coll" <info at elsitar.com> wrote:
> >
> > No one knows then ? Not even a hint or something ?
> >
> > 2015-12-23 13:15 GMT+01:00 Xavier Cardil Coll <info at elsitar.com>:
> >>
> >> Also, how to write a function to bypass cache entirely when a user logs
> in ?
> >>
> >> 2015-12-23 12:39 GMT+01:00 Xavier Cardil Coll <info at elsitar.com>:
> >>>
> >>> On Nginx cache, you can do this to avoid keep on caching when you add
> something to the cart in Woocommerce :
> >>>
> >>> Skip cache for WooCommerce query string
> >>>
> >>> if ( $arg_add-to-cart != "" ) {
> >>>       set $skip_cache 1;
> >>> }
> >>>
> >>> Skip cache when WooCommerce cart is not empty
> >>>
> >>> if ( $cookie_woocommerce_items_in_cart != "0" ) {
> >>>     set $skip_cache 1;
> >>> }
> >>>
> >>> How can you do this in Varnish ? With this config, wich was made
> specifically for Wordpress + Woocommerce, when you add something to cart,
> cache is not disable store wide so you get a mix of cached and non cache
> pages, cart gets emptied : http://pastebin.com/TuYeMtUZ
> >>>
> >>>
> >>> --
> >>>
> >>> ELSITAR
> >>>
> >>>
> >>
> >>
> >>
> >> --
> >>
> >> ELSITAR
> >>
> >>
> >
> >
> >
> > --
> >
> > ELSITAR
> >
> >
> >
> > _______________________________________________
> > varnish-misc mailing list
> > varnish-misc at varnish-cache.org
> > https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>
> Chill out, most of the people are in vacation :-)
>
> So, in varnish, by default, if the request contains a cookie, the cache is
> bypassed.
>
> But you can also force a pass, for example if the request contains a
> "foo-bar" header like so :
>
> sub vcl_recv {
>    if (req.http.foo-bar) {
>       return (pass);
>    }
> }
>
> For your needs, look at the query string and cookie vmods, it will allow
> to really fine-tune your workflow.
>
> And should you need more help, we are here :-)
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20151223/dbe55a00/attachment.html>


More information about the varnish-misc mailing list