menu

ZEIT

Our mission is to make cloud computing as easy and accessible as mobile computing. You can find our Next.js community here.

Channels
Chat
view-forward
# All channels
view-forward
# General
view-forward
# Announcements
view-forward
# Feature Requests
view-forward
# Hyper
view-forward
# Jobs
view-forward
# Micro
view-forward
# Now
view-forward
# PKG
view-forward
# Serve
view-forward
Team

Cache invalidation not working

November 27, 2018 at 11:27am

Cache invalidation not working

November 27, 2018 at 11:27am
Hi!
As of my understanding, each time you make a deployment or re-alias it, the cache should be invalidated.
Apparently, this is not happening for one of my assets, which still sees a CloudFlare HIT.
The asset was originally deployed with this route setting:
{"src" : "^/.+\\.(js|jpg|jpeg|gif|png|svg|txt)$", "headers": {"Cache-Control": "max-age=31536000"}}
And this morning I redeployed using:
{"src" : "^/.+\\.(js|jpg|jpeg|gif|png|svg|txt)$", "headers": {"Cache-Control": "s-maxage=31536000, max-age=300"}}
And when I try to download it (using httpie on the terminal), here's the headers:
HTTP/1.1 200 OK
CF-Cache-Status: HIT
CF-RAY: 48043d09a9f76f24-FCO
Cache-Control: max-age=31536000
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/javascript; charset=utf-8
Date: Tue, 27 Nov 2018 11:26:11 GMT
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Last-Modified: Thu, 22 Nov 2018 12:32:48 GMT
Server: cloudflare
Set-Cookie: __cfduid=d4574592b38549e7330b4004a427e3a2b1543317971; expires=Wed, 27-Nov-19 11:26:11 GMT; path=/; domain=.money.cowtech.it; HttpOnly
Vary: Accept-Encoding
X-Now-Cache: MISS
now: 1
x-now-trace: bru1
The thing is that if I just add a request header, like Origin, heres what I get:
HTTP/1.1 200 OK
CF-Cache-Status: MISS
CF-RAY: 480432b40d566f48-FCO
Cache-Control: s-maxage=31536000, maxage=300
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/javascript; charset=utf-8
Date: Tue, 27 Nov 2018 11:19:09 GMT
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Last-Modified: Tue, 27 Nov 2018 11:18:18 GMT
Server: cloudflare
Set-Cookie: __cfduid=d309c747f04a72648228a78a106eb564a1543317548; expires=Wed, 27-Nov-19 11:19:08 GMT; path=/; domain=.money.cowtech.it; HttpOnly
Vary: Accept-Encoding
X-Now-Cache: MISS
now: 1
x-now-trace: bru1
Can you please direct me on what was wrong and if there is a way to manually purge the cache?

November 27, 2018 at 1:04pm
Thank you for the report. A member of the team is investigating.
  • reply
  • like
Cool. I'll wait for the solution then :)
  • reply
  • like
Seeing a similar issue here (in Ann Arbor, Michigan). I'm getting stale content after deploy / aliasing. However, if I connect to a VPN in a different location, I get fresh content and different response headers.
ISP connection 👎
$ curl -I https://ray-tracer-challenge.now.sh/
HTTP/2 200
date: Tue, 27 Nov 2018 13:29:13 GMT
content-type: text/html; charset=utf-8
content-length: 3150
set-cookie: __cfduid=d8ea35ec4cad55f3cea71b4e6aa2a60901543325353; expires=Wed, 27-Nov-19 13:29:13 GMT; path=/; domain=.ray-tracer-challenge.now.sh; HttpOnly
last-modified: Tue, 27 Nov 2018 09:20:13 GMT
content-disposition: inline; filename="index.html"
etag: W/"4664b2206e3b97c1b1f2e3b2feb96adae82c544f"
cache-control: s-maxage=86400
access-control-allow-origin: *
x-now-trace: iad1,sfo1
now: 1
x-now-cache: MISS
x-now-id: d7vxq-1543310424846-oDQrhtrWb1xuKjf0gd3tkcdY
x-now-cache: MISS
x-now-id: v8cfd-1543310424618-pJhdUMneBRPudBMlosGEKrYf
cf-cache-status: HIT
accept-ranges: bytes
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 4804f1416ae67e7b-DTW
$ traceroute ray-tracer-challenge.now.sh
traceroute: Warning: ray-tracer-challenge.now.sh has multiple addresses; using 104.18.124.144
traceroute to ray-tracer-challenge.now.sh (104.18.124.144), 64 hops max, 52 byte packets
1 192.168.7.1 (192.168.7.1) 6.716 ms 4.588 ms 4.786 ms
2 96.120.40.189 (96.120.40.189) 15.511 ms 17.960 ms 15.443 ms
3 xe-8-3-0-sur01.wannarbor.mi.michigan.comcast.net (69.139.243.237) 16.508 ms 16.627 ms 15.474 ms
4 68.87.191.202 (68.87.191.202) 15.429 ms 18.053 ms 15.418 ms
5 be-152-ar02.pontiac.mi.michigan.comcast.net (162.151.63.73) 16.693 ms 19.368 ms 17.457 ms
6 69.252.92.110 (69.252.92.110) 16.602 ms 17.652 ms 16.800 ms
7 104.18.124.144 (104.18.124.144) 17.720 ms 17.938 ms 18.192 ms
VPN connection 👍
$ curl -I https://ray-tracer-challenge.now.sh/
HTTP/2 200
date: Tue, 27 Nov 2018 13:27:52 GMT
content-type: text/html; charset=utf-8
set-cookie: __cfduid=d19bce470a24ffad355c47f30534b618d1543325272; expires=Wed, 27-Nov-19 13:27:52 GMT; path=/; domain=.ray-tracer-challenge.now.sh; HttpOnly
cache-control: s-maxage=86400
last-modified: Tue, 27 Nov 2018 11:30:01 GMT
x-now-trace: iad1
now: 1
x-now-cache: MISS
cf-cache-status: HIT
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
server: cloudflare
cf-ray: 4804ef4a6ce73036-YYZ
$ traceroute ray-tracer-challenge.now.sh
traceroute: Warning: ray-tracer-challenge.now.sh has multiple addresses; using 104.18.125.144
traceroute to ray-tracer-challenge.now.sh (104.18.125.144), 64 hops max, 52 byte packets
1 10.137.0.1 (10.137.0.1) 41.366 ms 41.023 ms 39.347 ms
2 66.171.36.81 (66.171.36.81) 40.370 ms 40.125 ms 41.770 ms
3 te0-7-0-30.ccr21.cle04.atlas.cogentco.com (38.140.122.249) 50.750 ms 41.536 ms 41.927 ms
4 be2993.ccr31.yyz02.atlas.cogentco.com (154.54.31.226) 48.552 ms 50.433 ms 49.504 ms
5 38.88.240.186 (38.88.240.186) 59.597 ms 62.922 ms 63.238 ms
6 104.18.125.144 (104.18.125.144) 57.063 ms 58.357 ms 58.455 ms
  • reply
  • like
Hello! We have issued a fix, can you redeploy and/or realias and tell me if it is working as expected?
Edited
like-fill
1
  • reply
  • like
I'm having the same issue when aliasing.
  • reply
  • like
working now after a fresh deploy. Thank you!
  • reply
  • like

November 28, 2018 at 6:57am
It works for me as well. Thanks!
  • reply
  • like

January 3, 2019 at 3:06pm
I'm having a hard time finding documentation about the correct way to go about setting headers for static assets in 2.0. Is this the correct way to do this? setting a route with headers and no dest?
  • reply
  • like
I've relayed your feedback to the team. In the mean time, a route with CDN enabled (https://zeit.co/docs/v2/deployments/concepts/cdn-and-global-distribution/)
should be like this:
"routes": [
{ "src": "/static/(.*)", "headers": { "Cache-Control": "s-maxage=31536000" }, "dest": "/static/$1" }
]
}
If you want, "no dest" also works!
  • reply
  • like
ok great, thank you. to be clear, would something like this work? "src": ".*\.(js|jpg|jpeg|gif|png|svg|txt)$"
  • reply
  • like
Thanks! and if it helps, from my perspective I was looking in a few different spots for examples, but https://zeit.co/docs/v2/routing/caching/ might be ideal. I think this is a fairly common enough use case for folks, we used to be able to decare them directly here https://github.com/zeit/serve-handler#headers-array
  • reply
  • like
curious, that's using php's regex engine. for future reference, which engine is it using?
  • reply
  • like
curious, that's using php's regex engine. for future reference, which engine is it using?
I believe it is NGINX!
Also, I just created https://github.com/zeit/docs/issues/393. I encourage you to open an issue if you see room for improvements!
  • reply
  • like
GREAT, thanks
  • reply
  • like