Replies: 4 comments 12 replies
-
At first glance I thought this would be be a Cache abstraction on the server. Astro.cache() lead me towards the wrong direction while skimming the page. Personally I don't think that a higher-level API is needed. But if implemented I personally would recommend going with: This would make it 100% clear, that this is a SSR thing and you are only changing the response header and no caching is performed on the server. There even could be an easy error output if no Adapter is mentioned. |
Beta Was this translation helpful? Give feedback.
-
I don't think this abstraction is needed. Exposing |
Beta Was this translation helpful? Give feedback.
-
Is there a cache abstraction for SSR? Curious if it's possible to have a page rendered only once and reserved from the cache + having an eTAG resolved without re-rendering. |
Beta Was this translation helpful? Give feedback.
-
Is there any progress on this topic? This would be awesome! |
Beta Was this translation helpful? Give feedback.
-
Motivation
Cache headers are notoriously difficult to understand. While we should provide low-level access to modify response headers, it would also be nice for a higher-level API for setting cache headers.
Comparison
SvelteKit provides a
cache
object that can be returned from theload
function that looks like this:Next.js provides a
revalidate
option to set the number of seconds until the document should be refreshed.Proposal
A
Astro.cache()
method that can be used in frontmatter to set cache strategies for the current page. The function would be available on page and non-page components, enabling you to set caching in a higher-order component (such as in a layout component).The following common strategies will be supported. You can use more than on at a time (which is common).
stale-while-revalidate
Use the stale-while-revalidate strategy which serves a cached version for a number of seconds, while revalidating in the background.
maxAge
Set the max-age cache-control setting, signifying the number of seconds to cache.
public / private
Signifies where a public or private cache should be used. Private caches is for logged in user data.
immutable
Alternatives
The API
Astro.cache
could also be named:Astro.setCache
Astro.setCacheStrategies
Additionally, we could forgo this API entirely and have people set headers manually:
Beta Was this translation helpful? Give feedback.
All reactions