Skip to content

Public notes cache not invalidating properly after updates #10

@typelets

Description

@typelets

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] delete for 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 CDN

Suspected 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

  1. Reduce s-maxage for sheets - Use shorter CDN cache (e.g., 60s) for type: "sheets" since they're edited frequently

  2. Add cache-busting query param - Append ?v={timestamp} to public note URLs after update

  3. Use Cloudflare Cache Tags - More reliable purging via cache tags instead of URL-based purging

  4. Remove CDN caching for sheets entirely - Set s-maxage=0 for sheets, rely only on Redis

Files involved

  • src/lib/cloudflare-cache.ts - Cache headers and purge logic
  • src/lib/cache.ts - Redis cache utilities
  • src/lib/cache-keys.ts - Cache key definitions and TTLs
  • src/routes/public-notes/crud.ts - GET/PUT endpoints"

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions