@cryptotaxi247 / infra / commits / 40e0e539

Fix negative caching for cache.nixos.org

Eelco Dolstra committed Jun 23, 2022 at 22:59 UTC 40e0e539c2e4730dec595c9b73f1a540064f80ca
1 file changed +13 -10
terraform/cache.tf
+13 -10
@@ -180,14 +180,15 @@ resource "fastly_service_v1" "cache" {
180 source = "\"*\""
181 }
182
183 - response_object {
184 - name = "404-page"
185 - cache_condition = "is-404"
186 - content = "404"
187 - content_type = "text/plain"
188 - response = "Not Found"
189 - status = 404
190 - }
183 + # Serve a smaller 404 response. Unfortunately, this breaks caching.
184 + #response_object {
185 + # name = "404-page"
186 + # cache_condition = "is-404"
187 + # content = "404"
188 + # content_type = "text/plain"
189 + # response = "Not Found"
190 + # status = 404
191 + #}
192
193 snippet {
194 content = "set req.url = querystring.remove(req.url);"
@@ -211,15 +212,17 @@ resource "fastly_service_v1" "cache" {
212 }
213
214 snippet {
215 + name = "cache-errors"
216 content = <<-EOT
217 if (beresp.status == 403) {
218 set beresp.status = 404;
219 + }
220 + if (beresp.status == 404) {
221 set beresp.ttl = 86400s;
218 - set beresp.grace = 0s;
222 + set beresp.stale_if_error = 3600s;
223 set beresp.cacheable = true;
224 }
225 EOT
222 - name = "Change 403 from S3 to 404"
226 priority = 100
227 type = "fetch"
228 }