-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem
Public notes (especially sheets) show stale content after updates, even though cache invalidation appears to be working.
Current behavior
- User updates a sheet/note
- Backend logs show successful cache invalidation:
[CACHE] deletefor Redis[CLOUDFLARE] Cache purged successfully
- But users still see stale content
- Manually purging from Cloudflare dashboard fixes the issue
Current caching setup
Layer 1: Upstash Redis (src/lib/cache.ts)
- TTL: 24 hours (
CacheTTL.publicNote: 86400) - Deleted on update via
deleteCache(CacheKeys.publicNote(slug))
Layer 2: Cloudflare CDN (src/lib/cloudflare-cache.ts)
- Cache-Control header:
public, max-age=0, s-maxage=86400 - Purged on update via
purgePublicNoteCache(slug)
Update flow (src/routes/public-notes/crud.ts:407-409):
await deleteCache(CacheKeys.publicNote(slug)); // Upstash Redis
await purgePublicNoteCache(slug); // Cloudflare CDNSuspected cause
Cloudflare purge propagation delay across edge servers. The purge API returns success, but edge servers worldwide may take time to actually invalidate.
Potential solutions
-
Reduce
s-maxagefor sheets - Use shorter CDN cache (e.g., 60s) fortype: "sheets"since they're edited frequently -
Add cache-busting query param - Append
?v={timestamp}to public note URLs after update -
Use Cloudflare Cache Tags - More reliable purging via cache tags instead of URL-based purging
-
Remove CDN caching for sheets entirely - Set
s-maxage=0for sheets, rely only on Redis
Files involved
src/lib/cloudflare-cache.ts- Cache headers and purge logicsrc/lib/cache.ts- Redis cache utilitiessrc/lib/cache-keys.ts- Cache key definitions and TTLssrc/routes/public-notes/crud.ts- GET/PUT endpoints"