I've looked into ways to keep "everything" in cache as long as possible, and to clear only when and what something changes (max-age being a backup).
There are many ways to do this, and I like using especially rules + cache_action + expire with this module.

One, probably very common, usecase is that we want to clear varnish globally for all sites except the statically cached files, such as css, js, png, jpg, gif, ico, swf etc. I expected to find an regex purge rule *somewhere*, but after wasting lots of time trying to find one, I created it myself.

There were a few tricky parts, one of which is a bug in varnishadm: the regex needs to be escaped twice. The other trickiness is related to PCRE "negative lookbehind" syntax.

In the end what I came up with looks like:
^.*(?<!(\\.css|\\.gif|\\.png|\\.jpg|\\.ico|\\.swf|.\\.js))$

The ^ and $ need to be left out at least in if you use cache_actions + rules.

How to include this in varnish-module? Maybe by adding an option "Clear all except files ending in css, js, jpg, gif, png, ico, swf". This option could fire modified version of varnish_purge_all_pages() .

The original looks like this:

/**
 * Helper function to quickly flush all caches for the current site.
 */
function varnish_purge_all_pages() {
  $path = base_path();
  $host = _varnish_get_host();
  varnish_purge($host, $path);
}

and the new function could look like this:

/**
 * Helper function to quickly flush all caches for the current site.
 */
function varnish_purge_all_pages_excluding_assets() {
  $path = base_path() .  '.*(?<!(\\.css|\\.gif|\\.png|\\.jpg|\\.ico|\\.swf|.\\.js))';
  $host = _varnish_get_host();
  varnish_purge($host, $path);
}

I'm not totally sure, but maybe this needs even a third "\" escape :P?

Anyway, exposing this regex for editing would be even better.

PS: I also created an issue for this for cache_actions, where it could also be included separately: #1343052: Add to documentation: how to clear all pages except static assets

Comments

bibo’s picture

Issue summary: View changes

changed blocqkuote to code, or my regex wont show

mgifford’s picture

Status: Needs review » Active

There is no patch to review.

bibo’s picture

You're right, this issue is more like a public note about a specific use case.

I haven't found much use for this kind of Varnish purge recently, and looking at the lack of comments, seems like others haven't either.

esolitos’s picture

Priority: Normal » Minor

Is there any use of this? I mean, those are files, the load on the end http server shouldn't really influence the performances.

misc’s picture

Status: Active » Closed (won't fix)