Cache-Control configurable pour les fichiers media (S3 + db_storage) - #537
Draft
fabienheureux wants to merge 3 commits into
Draft
Cache-Control configurable pour les fichiers media (S3 + db_storage)#537fabienheureux wants to merge 3 commits into
fabienheureux wants to merge 3 commits into
Conversation
- Add MEDIA_CACHE_CONTROL constant backed by env var (default: 1h) - Wire it through S3 object_parameters for new uploads - Replace hardcoded value in db_storage ServeFileView - Add set_s3_cache_control backfill command for existing S3 objects
fabienheureux
marked this pull request as draft
July 1, 2026 12:35
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.
🎯 Objectif
Permettre de configurer l'en-tête
Cache-Controlsur les fichiers media (images, documents) servis via S3 ou le stockage base de données, et ajouter un backfill pour les objets existants.Jusqu'ici la valeur était hardcodée séparément dans
db_storage/views.py(max-age=3600) et absente du côté S3. Les navigateurs refaisaient donc une requête pour chaque image à chaque chargement de page.🔍 Implémentation
MEDIA_CACHE_CONTROLdansconfig/settings.py, initialisé depuis la variable d'environnementMEDIA_CACHE_CONTROLavecpublic, max-age=3600par défautobject_parameters[CacheControl]passé à django-storages pour que tous les nouveaux uploads aient le bon headerdb_storage/views.py: remplacement de la valeur hardcodée parsettings.MEDIA_CACHE_CONTROLset_s3_cache_controlpour backfill les objets S3 existants (--dry-runpour prévisualiser)Après déploiement, lancer sur les environnements S3 :
La variable d'environnement
S3_CACHE_CONTROLcontinue de surchargerMEDIA_CACHE_CONTROLspécifiquement pour le bucket S3 si besoin.Reste à faire