Replies: 7 comments 1 reply
|
I'm in favor of promoting this to Stage 2 |
|
I agree with the Goals here! I think it's ready for stage 2. |
|
Exciting to see! I'm in favor of promoting to Stage 2. |
|
This seems like a great direction! I think it is helpful for Astro to minimally abstract over underlying hosting primitives like this to enable users to more easily move between hosting providers. |
|
The fact that you can do this in top routes, but also in server island would be a killer feature for CMS driven websites! But, would the caching work if there is a session check or AB test inside a route? |
|
Sounds great! Would love to see this explored more. +1 to move to Stage 2. The idea of putting this responsibility fully in the developers hands (aka managing So for me, a big reason to take this this responsibility on as a framework is to be able to set good defaults. |
|
This has been moved to stage 2! Continue discussion here |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Astro route caching
Summary
Introduce a platform-agnostic route caching API for Astro SSR pages. This feature enables developers to declaratively define caching rules per route and dynamically override them in middleware or API handlers. It provides a consistent API across Node.js, Vercel, Netlify, Cloudflare, and other deployment targets, ensuring efficient caching while allowing cache invalidation by path or tag when supported. Where possible it will be implemented using CDN caches, but with fallback implemntations where this isn't supported.
Background & Motivation
Currently, caching in Astro SSR requires manually setting
Cache-ControlorCDN-Cache-Controlheaders, which vary per platform and is not ergonomic. Many modern frameworks offer built-in support for SSR caching strategies, allowing pages to be served efficiently while reducing function invocations and improving performance.Astro's current lack of a unified caching API means that users must implement custom caching solutions per deployment target, leading to unnecessary complexity. This proposal introduces a framework-level abstraction for caching that integrates seamlessly with Astro’s adapter system, providing an intuitive DX while using platform-specific caching mechanisms where available.
Goals
CacheStorage.Non-goals
fetchcache. This is for responses only.Example
Declarative API
Cache rules can be declared via route patterns in config:
They can be overridden in an Astro page or island's frontmatter:
Invalidation
Helper functions allow cache invalidation where the adapter supports it:
This uses adapter hooks under the hood, which call the platform-specific APIs. By providing a unified API, Astro ensures that caching is easy to configure while remaining adaptable to different hosting environments.
Adapter support
Each platform has slightly different levels of support, so would need to declare this via features. Where possible this would be implemented with
CDN-Cache-Controlheaders. Thecacheconfig could allow users to specify the header names, for example.We would implement an optional lightweight cache for the Node adapter using in-memory LRU, but would recommend using an external proxy or CDN cache.
All reactions