Does code belong in vcl_recv & vcl_fetch?

John spam at onlineconcepts.com
Thu May 9 22:47:34 CEST 2013


Using Varnish 3.0.2, I would like to cache a specific URL path. When
Varnish sends this path to the backend, Apache gathers data from external
services like Twitter.

Do I need to place this code in both the vcl_fetch and vcl_recv? I've
currently got it in both places, but I do not want to duplicate code
unless it's required (or a best practice).

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

# Respond to incoming requests.
sub vcl_recv {
[...]
# Always cache the following URLs to prevent frequent requests to external
# services. For example: Twitter at /ext/twittersearch
# This code appears twice, once here and again in vcl_fetch so make sure you
# edit both and keep them equal.
if (req.url ~ "^/ext/") {
  unset req.http.Cookie;
}

[...]

# Code determining what to do when serving items from the Apache servers.
# beresp == Back-end response from the web server.
sub vcl_fetch {
[...]
# Always cache the following URLs to prevent frequent requests to external
# services. For example: Twitter at /ext/twittersearch
# This code appears twice, once here and again in vcl_recv so make sure you
# edit both and keep them equal.
if (req.url ~ "^/ext/") {
  unset req.http.Cookie;
}

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Rather than post my entire VCL file, I'll just say that I modeled it on
this one.

https://fourkitchens.atlassian.net/wiki/display/TECH/Configure+Varnish+3+for+Drupal+7

I've also found this article helpful.
http://www.lullabot.com/blog/articles/configuring-varnish-high-availability-multiple-web-servers

TIA,
John



More information about the varnish-misc mailing list