mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-08-22 21:11:21 +08:00
refactor: adjust fall-through order of caching scenarios
This commit is contained in:
parent
4cb20f7f88
commit
0e524c8c28
12
server.py
12
server.py
@ -57,19 +57,19 @@ async def cache_control(request: web.Request, handler: Callable[[web.Request], A
|
|||||||
if request.path.endswith('.js') or request.path.endswith('.css') or request.path.endswith('index.json'):
|
if request.path.endswith('.js') or request.path.endswith('.css') 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):
|
elif request.path.lower().endswith(IMG_EXTENSIONS):
|
||||||
if 200 <= response.status < 300:
|
if response.status == 304:
|
||||||
response.headers.setdefault('Cache-Control', f"public, max-age={ONE_DAY}")
|
|
||||||
elif response.status == 304:
|
|
||||||
# 304 Not Modified - don't set cache headers, inherit from original
|
# 304 Not Modified - don't set cache headers, inherit from original
|
||||||
pass
|
pass
|
||||||
elif response.status in (301, 308):
|
elif response.status == 404:
|
||||||
|
response.headers.setdefault('Cache-Control', f"public, max-age={ONE_HOUR}")
|
||||||
|
elif 200 <= response.status < 300:
|
||||||
|
response.headers.setdefault('Cache-Control', f"public, max-age={ONE_DAY}")
|
||||||
|
elif response.status == 301 or response.status == 308:
|
||||||
# Permanent redirects - cache for 1 day
|
# Permanent redirects - cache for 1 day
|
||||||
response.headers.setdefault('Cache-Control', f"public, max-age={ONE_DAY}")
|
response.headers.setdefault('Cache-Control', f"public, max-age={ONE_DAY}")
|
||||||
elif 300 <= response.status < 400:
|
elif 300 <= response.status < 400:
|
||||||
# Temporary redirects (302, 303, 307) and other 3xx - no cache
|
# Temporary redirects (302, 303, 307) and other 3xx - no cache
|
||||||
response.headers.setdefault('Cache-Control', 'no-cache')
|
response.headers.setdefault('Cache-Control', 'no-cache')
|
||||||
elif response.status == 404:
|
|
||||||
response.headers.setdefault('Cache-Control', f"public, max-age={ONE_HOUR}")
|
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user