Hi.
I'm implementing an on-demand SSR route with dynamic params like:
- /food/[type]/[variation]
I need to validate params against an external API, with these constraints:
- External API must be called server-side only (never from client/browser)
- Validation order must be:
- validate [type]
- then validate variation (because variation options depend on food type)
Desired behaviour:
- Fetch and cache the full valid food types list once (e.g. cache key: food-types).
- For each request, validate type from that cached dataset first.
- Only if valid, proceed to "variation" validation (which may use a second cache key like food-types:{type}).
- Avoid repeated upstream API calls for random invalid route attempts (such as /food/apple/asdasd)
- Be able to invalidate these cache entries from an API endpoint (e.g. /api/revalidate) when upstream data changes.
Main uncertainty:
My understanding is that default Astro/page caching is only tied to rendered pages, not to internal upstream fetches; so without explicit data caching, requests to new dynamic URLs (including invalid params) would still execute server logic and potentially re-hit the external API. Is that correct?
Questions
- What is the recommended Astro pattern for shared server-side data caching across dynamic SSR requests?
- Are there Astro-native APIs/features that help enforce this validation/caching flow cleanly, or is my only option to look at other options such as Redis etc?
Thanks!