Replies: 6 comments 14 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.
-
|
I made a library as a generic abstraction to help with this. The README includes an example using Astro. https://github.com/ascorbic/cdn-cache-control |
Beta Was this translation helpful? Give feedback.
-
|
One thing we might want to do is implement optional built-in caching in the Node adapter. Hosts with their own CDN are able to use their built-in caching, but self-hosted node might benefit from an ability to do server caching. I'm assuming there are middleware modules out there that are designed to handle this sort of thing. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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
cacheobject that can be returned from theloadfunction that looks like this:Next.js provides a
revalidateoption 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.cachecould also be named:Astro.setCacheAstro.setCacheStrategiesAdditionally, we could forgo this API entirely and have people set headers manually:
Beta Was this translation helpful? Give feedback.
All reactions