API cache headers

I am trying to take advantage of as much caching as possible with Prismic’s REST API but I am seeing some strange behavior related to HTTP caching.

I am using the JS SDK with this query

  const section = await api.getByUID('section', 'test-section');

This results in this Network request: https://sean-prismic-demo.cdn.prismic.io/api/v2/documents/search?page=1&pageSize=1&ref={"_tracker"%3A"aYrLbFSk"}&q=[[at(my.section.uid%2C%20"test-section")]]

But the response headers seem to disable caching at all layers (e.g. CDN, browser):

cache-control: max-age=0, no-store
pragma: no-cache

Since Prismic.io uses the master-ref to control versioning, it seems like it should be safe to cache at all layers, so how can I enable this?

Hello @sconnolly!

Thank you for reaching out to us and sorry for the delay. Are you still having this issue, I’m not personally familiar with this issue but if you could give us more details on it we can investigate.

Hi @paulina.gavilan,

What sort of details do you need?

@sconnolly, like, how are you implementing these method and/or share any error logs that you’ve been getting.

I missed to tell you before that we don’t recommend using a caching system as this can cause issues because the master ref is updated every time a document is changed and this can cause websites to break.

@paulina.gavilan as I wrote before, I am implementing with the prismic SDK:

const section = await api.getByUID('section', 'test-section');

I understand the ref may change, so I’m not doing any sort of cacheing on the endpoint used to get the current version of the API, but there are multiple articles like this one from prismic about the immutability of prismic documents, so I would expect documents to be cacheable as long as the proper ref is used.

Hey, @sconnolly we are already caching the different documents at the first request on our CDN based on the ref (that is included in the URL). is the CDN caching not sufficient for you?

@renaud Is it though? I'm still confused by the no-cache headers that would normally disable caching. And why would you prevent the browser from caching the same request?

Hey @sconnolly the URL that you sent is pretty specific, if you look at the ref, it's not really the master ref that your API provides to all your users. It's a specific ref that is aiming to track your request in order to display the documents that you fetched in the Edit Button.

If you access your page in incognito mode (Not logged in into prismic) you should see something like :

For this request, the response header will be

Does that makes sense?

This issue has been closed due to inactivity.