Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-cache should store the result to cache #424

Open
PaleNeutron opened this issue May 9, 2024 · 0 comments · May be fixed by #425
Open

no-cache should store the result to cache #424

PaleNeutron opened this issue May 9, 2024 · 0 comments · May be fixed by #425

Comments

@PaleNeutron
Copy link

See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control#no-cache

The no-cache response directive indicates that the response can be stored in caches, but the response must be validated with the origin server before each reuse, even when the cache is disconnected from the origin server.

This implementation make no-cache actually no-store:

def _uncacheable(request: Optional[Request]) -> bool:
"""Determine if this request should not be cached
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"
"""
if not FastAPICache.get_enable():
return True
if request is None:
return False
if request.method != "GET":
return True
return request.headers.get("Cache-Control") in ("no-store", "no-cache")

PaleNeutron pushed a commit to PaleNeutron/fastapi-cache that referenced this issue May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant