How can I issue a wildcard purge? For example, it appears that "node/[nid]/comments?page=1" is getting cached separately from "node/[nid]/comments?page=2"?

Comments

djbobbydrake’s picture

I had to update my varnish default.vcl file to include the following:

purge("req.url ~ ^" req.url " && req.http.host == " req.http.host);
djbobbydrake’s picture

Actually, my suggestion is kind of dangerous... there would definitely be unintended cache flushes...

SqyD’s picture

I have to confess I kinda saw this one (and #1304812: Expire all pages likewise ) coming ;-) I've known all along it's very well possible to implement this kind of stuff as Tollef from Varnish taught me himself. When implementing views/panels/etc stuff in the future in expire this may be a viable option when implemented smart enough on the other side of that hook.

The same notion of it being kinda dangerous in most of my personal use cases held me back from implementing it so far. It's one of my objections to the existing Varnish module for Drupal that does implement this kind of features and why I like the Cache Expiration module approach. Will need to have have good permissions and some sensible limiting to the number of requests and wildcards and or course proper default configuration:
flush all caches = 0 DANGER!! Setting this option will seriously harm our natural environment and kill bunnies!
... or leave it hidden outside the gui for us to abuse and/or be heroic when disaster hits ;-)

SqyD’s picture

Version: 6.x-1.3 » 7.x-2.x-dev
elijah lynn’s picture

Issue summary: View changes
Related issues: +#2408671: Expire module wildcard support
elijah lynn’s picture

Status: Active » Needs review
StatusFileSize
new696 bytes

Here is a patch that implements a wildcard purge at the API level for this module. By API level I mean that we are using this module just for the purge_urls() function and passing it an array of URLs directly. In the URL we pass we have a * at the end. This patch turns it into a .* which is a regex that the Varnish 'ban' function needs. This needs a corresponding change in the VCL file, we used the below for ours:

if (req.request == "PURGE") {
  # Add support for wildcard purging.
  # @see http://twigstechtips.blogspot.com/2014/04/varnish-enabling-wildcard-purging-of.html
  ban("req.http.host == " + req.http.host + " && req.url ~ " + req.url + "$");
  error 200 "Purged.";
  return(lookup);
}

This patch in particular depends on this https://www.drupal.org/node/2680793#comment-10930819 patch because we also escape all the parts of the URL that might be considered regex.

Sorry, this is a bit complicated right now but I figured I would at least post it.

elijah lynn’s picture

StatusFileSize
new766 bytes

Added better comment to link back here for corresponding VCL change.