Skip to content

feat: CDN caching for avatar images#6

Merged
BH3GEI merged 1 commit into
mainfrom
feat/06-cdn-cache
May 21, 2026
Merged

feat: CDN caching for avatar images#6
BH3GEI merged 1 commit into
mainfrom
feat/06-cdn-cache

Conversation

@BH3GEI

@BH3GEI BH3GEI commented May 21, 2026

Copy link
Copy Markdown
Member

Summary

  • Add Cache-Control: public, max-age=86400 header to /api/avatars/{id}/image and /api/avatars/{id}/thumbnail endpoints
  • Enables Cloudflare to cache static avatar images for 24 hours, reducing origin load

Test plan

  • curl -sI https://dh.mofa.ai/api/avatars/firefighter/thumbnail | grep -i cache shows Cache-Control header
  • Avatar images still load correctly on the frontend

Set Cache-Control: public, max-age=86400 on /api/avatars/{id}/image
and /api/avatars/{id}/thumbnail responses so Cloudflare can cache
static avatar assets for 24 hours.
Copilot AI review requested due to automatic review settings May 21, 2026 16:39
@BH3GEI BH3GEI merged commit acf4815 into main May 21, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds CDN-friendly caching headers to avatar image and thumbnail endpoints so Cloudflare (and other shared caches) can cache these static assets for 24 hours and reduce origin load.

Changes:

  • Introduced a shared _CDN_CACHE_HEADERS constant (Cache-Control: public, max-age=86400).
  • Applied these cache headers to /api/avatars/{id}/image responses (preset + uploaded).
  • Applied these cache headers to /api/avatars/{id}/thumbnail responses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app.py
Comment on lines 163 to +167
meta = _load_meta()
if avatar_id in meta:
path = UPLOADS_DIR / meta[avatar_id]["file"]
if path.exists():
return FileResponse(path)
return FileResponse(path, headers=_CDN_CACHE_HEADERS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants