Conversation
Added cache configuration for routes in astro.config.ts and updated cache invalidation tag in webhook API.
|
I’d like to see a summary of the total cache along with a list of tags, so we can get an idea of what’s being cached or invalidated and catch any tags that might have been missed which allows us to easily debug. |
|
I'm not sure that's something for Astro to provide, feels like maybe it should be achievable through the driver platform (eg. cloudflare)? |
|
Exclusively for self-hosted servers, these metrics (memory, SWR settings, etc.) are provided in JSON format. I think they could be useful for storefronts that need to cache product listings. Other ideas, can it cache payload in gzipped or brotli? Thinking by 50% or more is worth saving and reduce latency. |
|
From the perspective of Sanity I think we'd like to automatically define cache tags since our backend provides them, regardless of how customers define their GROQ queries and how the data is fetched, it's fairly dynamic. For us if we can define a live loader that could call A blog post could be resolving an author reference. If the author reference is edited it should invalidate all post entries that use it. Since customers often fetch data from other sources than ours we can't make any assumptions on their For next.js we're able to do this by calling |
|
I've been going through the RFC and made some changes to clarify things, tidy things up etc.
|
proposals/0056-route-caching.md
Outdated
| export default defineConfig({ | ||
| adapter: node(), | ||
| cache: { | ||
| routes: { |
There was a problem hiding this comment.
This makes me think about https://nitro.build/config#routerules in nitro. So I'm wondering: is there any benefit to have this under cache? Instead that could be on the top level and we could also set prerender: boolean there.
So to recap, this looks good to me as is but maybe there's a way to future proof it and enable more cool things
There was a problem hiding this comment.
hmm, yeah. Good idea. routeRules would be a better name in that scneario too
There was a problem hiding this comment.
I wonder if we just directly copy the Nitro pattern, with "swr: true|number is shortcut for cache: { swr: true, maxAge: number }"
There was a problem hiding this comment.
A recurring problem with supporting different shapes it doesn't work very nicely with updateConfig(). Otherwise no strong opinion
|
|
||
| Caching is essential for performant server-rendered applications, but current solutions have significant limitations: | ||
|
|
||
| **Platform-specific implementations**: Most caching solutions (like ISR) are tightly coupled to specific hosting platforms. ISR was created for Next.js on Vercel and while other platforms have implemented versions of it, they're often limited or second-class implementations. This creates vendor lock-in and inconsistent behavior across deployments. |
There was a problem hiding this comment.
What does that mean for https://docs.astro.build/en/guides/integrations-guide/vercel/#isr? Would we remove it in favor of Astro.cache using https://vercel.com/changelog/tag-based-cache-invalidation-now-available-for-all-responses under the hood?
There was a problem hiding this comment.
I think so, or leave it deprecated and make it conflice with the new caching
| - **Distributed caching for Node.js**: Node adapter uses in-memory cache, unsuitable for multi-instance deployments without external cache | ||
| - **Static/prerendered page caching**: This is for on-demand SSR routes only; static and prerendered routes are already cached by default and don't need route-level cache control | ||
| - **Partial page caching**: This focuses on full-page route caching, not fragment or component-level caching | ||
| - **Browser caching**: This focuses on CDN and server-side caching, not browser caching. Only `Last-Modified` and `ETag` headers are sent to browsers for conditional requests |
There was a problem hiding this comment.
Can users access the current state of the cache (eg. after several cache.set() calls) so they can use this data to add browser caching headers? So not only Astro.cache.tags
|
|
||
| ```ts | ||
| interface CacheProvider { | ||
| name: string; |
There was a problem hiding this comment.
It's probably more useful to have the name in the cache.provider than the runtime implementation, so it can be used in logging etc
….routes to top-level routeRules
|
@florian-lefebvre I have done an update that among other things moves the rules from |
…bledAstroCache, node LRU details)
da2f27a to
723f177
Compare
Memory cache moved to core. Config function is now memoryCache() from astro/config instead of cacheMemory() from @astrojs/node/cache.
Summary
A platform-agnostic route caching API for Astro SSR pages that enables declarative cache control using web standards.
Examples
Basic route caching
Automatic dependency tracking
Links