Don't cache large files

Jason Heffner jdh132 at psu.edu
Thu Apr 16 18:05:33 CEST 2015


I’m working on updating our Varnish 3 config to Varnish 4 and I was able to figure out how to have the same functionality for almost all of the config. I wanted to find opinions on how to handle large files. We don’t want to cache any large files and had this in place for varnish 3. I’ve read streaming instead of piping was a solution but found nothing to determine this based solely on file size from the backend.

# Varnish 3 config
added to vcl_recv:
  /* Bypass cache for large files.  The x-pipe header is
     set in vcl_fetch when a too large file is detected. */
  if (req.http.x-pipe && req.restarts > 0) {
    remove req.http.x-pipe;
    return (pipe);
  }

added to vcl_fetch:
  # don't cache files larger than 10MB
  /* Don't try to cache too large files.  It appears
     Varnish just crashes if we don't filter them. */
  if (beresp.http.Content-Length ~ "[0-9]{8,}" ) {
    set req.http.x-pipe = "1";
    return (restart);
  }

Since req.* is no longer available in vcl_recv this code doesn’t function anymore.

Thanks,
Jason


More information about the varnish-misc mailing list