Are Functions with Query Strings Really Cached Now?

Continuing the discussion from Netlify Function with query strings ignores custom Cache-Control header:

Netlify recently enabled query based caching of functions. But is it working?

Here are a few curl requests to the demo site:


> curl -I https://remix-query-cache-demo.netlify.app/?hello=saturn

HTTP/2 200
age: 0
cache-control: max-age=60, s-maxage=60
content-type: text/html
date: Sun, 10 Apr 2022 01:24:02 GMT
server: Netlify
x-nf-request-id: 01G08H48E5RX0SAZFZNCF1HY5Q

> curl -I https://remix-query-cache-demo.netlify.app/?hello=saturn

HTTP/2 200
age: 0
cache-control: max-age=60, s-maxage=60
content-type: text/html
date: Sun, 10 Apr 2022 01:24:05 GMT
server: Netlify
x-nf-request-id: 01G08H4B0J7T4YHPKS7PNSTJFH

> curl -I https://remix-query-cache-demo.netlify.app/?hello=saturn

HTTP/2 200
age: 0
cache-control: max-age=60, s-maxage=60
content-type: text/html
date: Sun, 10 Apr 2022 01:24:39 GMT
server: Netlify
x-nf-request-id: 01G08H5CS2W7KQ0Y7Y2ZD7KZVT

> curl -I https://remix-query-cache-demo.netlify.app/?hello=saturn

HTTP/2 200
age: 0
cache-control: max-age=60, s-maxage=60
content-type: text/html
date: Sun, 10 Apr 2022 01:24:42 GMT
server: Netlify
x-nf-request-id: 01G08H5FB41ACC5EAYKJ1RY9NW

Notice that the “age” header is always “0”. That’s pretty clear indication that it isn’t a cache hit, but a miss. In contrast, requests to the bare URL (without the query strings) do seem to be cached. Serial curl requests will yield, Age headers > 0.

Am I missing something here @perry and @hrishikesh ? Did the new changes break recently?

Hey @swamidass,

I don’t know why curl is showing age always 0, but browsers seem to work fine.

The response is cached for a minute. So after multiple reloads, I was able to see the age header go up to a min after which is returned back to 0.

1 Like

I seemed not to be working in the browser either…

Has Netlify considered adding a response header that indicates if a response is a cache HIT or MISS? That would help in debugging…

Also, I just tried doing this again with curl, and it appears to work now. It seems that it was somehow fixed since I posted the OP?

Regardless…

Yes, it was discussed internally before but we decided not to go forward with that. We can file it as a feature request if you want, but it might not get implemented soon.

1 Like

When you were focused primarily on static content, cache headers made sense to exclude.

However, with the line blurring, and more and more dynamic content appearing in Jamstack, I do think this is an important feature. For example. Vercel has some custom response headers to convey the cache status.

I’m not sure your caching backend but it should not be too difficult to add a HIT/MISS response header.

Yes, we’re aware of that and it was not abandoned due to engineering efforts. There were multiple problems put forth in the discussion, due to which the thought was abandoned.

Sure, it is not permanently closed, we can re-open it for discussion. Thank you for the feedback.

1 Like