Skip to content

Instantly share code, notes, and snippets.

@aondio
Created June 16, 2020 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aondio/b3dbbaf8ed2b230019165e2ceec30655 to your computer and use it in GitHub Desktop.
Save aondio/b3dbbaf8ed2b230019165e2ceec30655 to your computer and use it in GitHub Desktop.
VCP layer:
v_b_r:
# Simply use caching headers. Nothing relevant here.
if beresp.http.X-VCP-Ttl > 0:
beresp.ttl = beresp.http.X-VCP-Ttl
beresp.grace = beresp.http.X-VCP-Grace
beresp.keep = beresp.http.X-VCP-Keep
else:
# Let built-in VCL transform this in a HFM.
beresp.ttl = 0s
vcl_deliver:
unset resp.http.X-VCP-{Ttl,Grace,Keep}
if !obj.uncacheable && resp.http.X-CDN-Ttl > 0:
if obj.ttl > 0:
# We're delivering a fresh object to the CDN layer. 'Age'
# needs to be adjusted in order to ensure (1) it will be
# cached in the CDN layer; and (2) it won't cached longer
# than the remaining lifetime of the object as a fresh
# candidate.
if resp.http.X-CDN-Ttl > obj.ttl:
resp.http.Age = resp.http.X-CDN-Ttl - obj.ttl
else:
resp.http.Age = 0
else:
# Object might be cached in the CDN layer. We need to keep
# 'Age' as calculated by VCP. TTL, grace & keep will be
# adjusted in the CDN taking the 'Age' value into account.
# Beware if 'resp.http.X-CDN-Ttl' < 'resp.http.Age' a HFM
# will be generated in the CDN layer due to built-in v_b_r!
# XXX: perhaps a more sensible approach would be avoiding
# this case as much as possible setting 'req.grace = 0'
# during 'vcl_recv' when backend is healthy.
else:
# Object was not cached in this layer or it won't be cached in
# the CDN layer. We can keep 'Age' or drop it here. Whatever
# is best for the client side.
CDN layer:
v_b_r:
# Simply use caching headers. Nothing relevant here.
if beresp.http.X-CDN-Ttl > 0:
beresp.ttl = beresp.http.X-CDN-Ttl
beresp.grace = beresp.http.X-CDN-Grace
beresp.keep = beresp.http.X-CDN-Keep
else:
# Let built-in VCL transform this in a HFM.
beresp.ttl = 0s
vcl_deliver:
unset resp.http.X-CDN-{Ttl,Grace,Keep}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment