Cloudflare Cache versus D1 freshness: why a fast page can show stale data
Trace browser, edge and application caches when freshly published content does not appear on the public site.
Cache performance and correctness are different goals
A Worker may read D1 and generate HTML that can be cached where appropriate. That reduces load, but the cached response can continue showing an old article, cover or news item after publication. A successful database write and an up-to-date public page are separate events. An admin success message should not automatically imply globally refreshed content.
Distinguish each caching layer
Browser caching, edge response caching, in-process short-lived data and media URLs are different components. Investigate Cache-Control headers, version parameters and HTTP status codes to identify the responsible layer. The Cloudflare Workers Cache API is local to the data center handling a request; cached entries are not automatically replicated across every location.
Define an explicit freshness contract
Short TTLs may be reasonable for public archive pages. If new admin content must appear immediately, consider versioned response keys or appropriate invalidation. Unique media object keys tied to content hashes help avoid serving old image bytes. Never place personalized or authenticated responses into a shared public cache without appropriate controls.
Verify both storage and public visibility
After publishing, verify the D1 row and R2 object first; then fetch the same page anonymously and inspect its HTML. Compare responses under different cache states, as well as desktop and mobile layouts. If D1 is correct but the page is stale, focus on caching instead of re-running imports. Repeating database writes can create unnecessary cost without solving the root cause.
Comments
0 real commentsNo real reader comments yet.
✎ Write a comment