same problem, I’m using varnish cache who ignore cache in that situations:
// Do not cache AJAX requests.
if (req.http.X-Requested-With == "XMLHttpRequest") {
return(pass);
}
// Post requests will not be cached
if (req.http.Authorization || req.method == "POST") {
return (pass);
}
// Only cache GET or HEAD requests. This makes sure the POST requests are always passed.
if (req.method != "GET" && req.method != "HEAD") {
return (pass);
}
// Dont Cache WordPress post pages and edit pages
if (req.url ~ "(wp-admin|post\.php|edit\.php|wp-login|et_fb=)") {
return(pass);
}
if (req.url ~ "/wp-cron.php" || req.url ~ "preview=true") {
return (pass);
}
// Woocommerce
if (req.url ~ "(cart|my-account|checkout|addons)") {
return (pass);
}
if ( req.url ~ "\?add-to-cart=" ) {
return (pass);
}
// Paid memberships Pro PMP
if ( req.url ~ "(membership-account|membership-checkout)" ) {
return (pass);
}
// WordPress Social Login Plugin. Note: Need to develop this. Please share if you have an example.
if (req.url ~ "(wordpress-social-login|wp-social-login)") {
return (pass);
}
// Remove the "has_js" cookie
set req.http.Cookie = regsuball(req.http.Cookie, "has_js=[^;]+(; )?", "");
// Remove any Google Analytics based cookies
set req.http.Cookie = regsuball(req.http.Cookie, "__utm.=[^;]+(; )?", "");
set req.http.Cookie = regsuball(req.http.Cookie, "_ga=[^;]+(; )?", "");
set req.http.Cookie = regsuball(req.http.Cookie, "utmctr=[^;]+(; )?", "");
set req.http.Cookie = regsuball(req.http.Cookie, "utmcmd.=[^;]+(; )?", "");
set req.http.Cookie = regsuball(req.http.Cookie, "utmccn.=[^;]+(; )?", "");
// Remove the Quant Capital cookies (added by some plugin, all __qca)
set req.http.Cookie = regsuball(req.http.Cookie, "__qc.=[^;]+(; )?", "");
// Remove the wp-settings-1 cookie
set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-1=[^;]+(; )?", "");
// Remove the wp-settings-time-1 cookie
set req.http.Cookie = regsuball(req.http.Cookie, "wp-settings-time-1=[^;]+(; )?", "");
// Remove the wp test cookie
set req.http.Cookie = regsuball(req.http.Cookie, "wordpress_test_cookie=[^;]+(; )?", "");
// Remove the phpBB cookie. This will help us cache bots and anonymous users.
set req.http.Cookie = regsuball(req.http.Cookie, "style_cookie=[^;]+(; )?", "");
set req.http.Cookie = regsuball(req.http.Cookie, "phpbb3_psyfx_track=[^;]+(; )?", "");
// Remove the cloudflare cookie
set req.http.Cookie = regsuball(req.http.Cookie, "__cfduid=[^;]+(; )?", "");
// Remove the PHPSESSID in members area cookie
set req.http.Cookie = regsuball(req.http.Cookie, "PHPSESSID=[^;]+(; )?", "");
// Are there cookies left with only spaces or that are empty?
if (req.http.cookie ~ "^\s*$") {
unset req.http.cookie;
}
// MEGA DROP. Drop ALL cookies sent to WordPress, except those originating from the URLs defined.
// This increases HITs significantly, but be careful it can also break plugins that need cookies.
// Note: The /members/ directory had problems with PMP login and social login plugin.
// Adding it to the exclude list here (and including it below in the "Retain cookies" list) fixed login.
// This works better than than other cookie removal examples found on varnish's website.
// Note phpBB directory (forumPM) also passes cookies here.
if (!(req.url ~ "(wp-login|wp-admin|cart|my-account|checkout|addons|wordpress-social-login|wp-login\.php|forumPM|members)")) {
unset req.http.cookie;
}