feat: CDN caching for avatar images#6
Merged
Merged
Conversation
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.
There was a problem hiding this comment.
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_HEADERSconstant (Cache-Control: public, max-age=86400). - Applied these cache headers to
/api/avatars/{id}/imageresponses (preset + uploaded). - Applied these cache headers to
/api/avatars/{id}/thumbnailresponses.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cache-Control: public, max-age=86400header to/api/avatars/{id}/imageand/api/avatars/{id}/thumbnailendpointsTest plan
curl -sI https://dh.mofa.ai/api/avatars/firefighter/thumbnail | grep -i cacheshows Cache-Control header