mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-24 20:47:54 +00:00
Merge branch 'fix-no-cache' into fix
This commit is contained in:
@@ -72,7 +72,7 @@ def _uncacheable(request: Optional[Request]) -> bool:
|
||||
Returns true if:
|
||||
- Caching has been disabled globally
|
||||
- This is not a GET request
|
||||
- The request has a Cache-Control header with a value of "no-store" or "no-cache"
|
||||
- The request has a Cache-Control header with a value of "no-store"
|
||||
|
||||
"""
|
||||
if not FastAPICache.get_enable():
|
||||
@@ -81,7 +81,7 @@ def _uncacheable(request: Optional[Request]) -> bool:
|
||||
return False
|
||||
if request.method != "GET":
|
||||
return True
|
||||
return request.headers.get("Cache-Control") in ("no-store", "no-cache")
|
||||
return request.headers.get("Cache-Control") == "no-store"
|
||||
|
||||
|
||||
def cache(
|
||||
@@ -182,7 +182,7 @@ def cache(
|
||||
)
|
||||
ttl, cached = 0, None
|
||||
|
||||
if cached is None: # cache miss
|
||||
if cached is None or (request is not None and request.headers.get("Cache-Control") == "no-cache") : # cache miss
|
||||
result = await ensure_async_func(*args, **kwargs)
|
||||
to_cache = coder.encode(result)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user