Created
October 11, 2023 18:34
-
-
Save peterroelants/792e62172e086dfab19edb3ab63f594a to your computer and use it in GitHub Desktop.
FastAPI Cache-Control : no-cache
This file contains 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
from fastapi import FastAPI | |
from fastapi.staticfiles import StaticFiles | |
class StaticNoCache(StaticFiles): | |
"""Disable caching of static files serverd""" | |
def is_not_modified(self, *args, **kwargs) -> bool: | |
return False | |
def file_response(self, *args, **kwargs): | |
resp = super().file_response(*args, **kwargs) | |
resp.headers["Cache-Control"] = "no-cache" | |
return resp | |
app = FastAPI() | |
app.mount("/static", StaticNoCache(directory="./static_files"), name="static") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment