Astro CF Blog
Home
Blog
Admin
← Back to Admin
Edit Post
Demo Mode
— Calls
PATCH /api/posts/how-caching-works
with the dev secret.
Slug
Read-only — changing the slug would break existing links.
Title
Excerpt
Short summary shown on the blog listing page.
Content
Markdown supported:
# H1
,
## H2
,
**bold**
,
*italic*
,
`code`
# How On-Demand Revalidation Works ## The Flow 1. **First request** — middleware checks `caches.default` (miss), renders the page, stores it, returns it with `Cache-Control: public, s-maxage=31536000`. 2. **Subsequent requests** — middleware finds the cached entry (hit) and returns it instantly — no D1 query, no rendering. 3. **Publishing a post** — the `/api/posts` endpoint inserts into D1, then calls `caches.default.delete()` for `/` and `/blog`. 4. **Next request** — cache miss again, fresh render picks up the new post, re-cached. ## Why not Cloudflare CDN cache headers alone? `Cache-Control` headers tell Cloudflare's CDN to cache, but you cannot purge individual URLs without a paid Cache Purge API plan. The **Cache API** (`caches.default`) is per-worker, gives you programmatic `put` / `delete` control, and is free.
Published
Save Changes
Revalidate Cache Only
Cancel
View post →