mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-08-30 06:23:29 +08:00
refactor: guard clause before image caching logic
This commit is contained in:
parent
7cd68913d4
commit
8544db8667
@ -32,15 +32,21 @@ async def cache_control(
|
|||||||
or request.path.endswith("index.json")
|
or request.path.endswith("index.json")
|
||||||
):
|
):
|
||||||
response.headers.setdefault("Cache-Control", "no-cache")
|
response.headers.setdefault("Cache-Control", "no-cache")
|
||||||
elif request.path.lower().endswith(IMG_EXTENSIONS):
|
return response
|
||||||
if response.status == 404:
|
|
||||||
response.headers.setdefault("Cache-Control", f"public, max-age={ONE_HOUR}")
|
# Early return for non-image files - no cache headers needed
|
||||||
elif response.status in (200, 201, 202, 203, 204, 205, 206, 301, 308):
|
if not request.path.lower().endswith(IMG_EXTENSIONS):
|
||||||
# Success responses and permanent redirects - cache for 1 day
|
return response
|
||||||
response.headers.setdefault("Cache-Control", f"public, max-age={ONE_DAY}")
|
|
||||||
elif response.status in (302, 303, 307):
|
# Handle image files
|
||||||
# Temporary redirects - no cache
|
if response.status == 404:
|
||||||
response.headers.setdefault("Cache-Control", "no-cache")
|
response.headers.setdefault("Cache-Control", f"public, max-age={ONE_HOUR}")
|
||||||
# Note: 304 Not Modified falls through - no cache headers set
|
elif response.status in (200, 201, 202, 203, 204, 205, 206, 301, 308):
|
||||||
|
# Success responses and permanent redirects - cache for 1 day
|
||||||
|
response.headers.setdefault("Cache-Control", f"public, max-age={ONE_DAY}")
|
||||||
|
elif response.status in (302, 303, 307):
|
||||||
|
# Temporary redirects - no cache
|
||||||
|
response.headers.setdefault("Cache-Control", "no-cache")
|
||||||
|
# Note: 304 Not Modified falls through - no cache headers set
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user