fix: recognize POST method as cacheable #546
Open
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I am using
fastapi-cache
for my project and encountered a small issue regarding request caching. Currently, the_uncachable
function allows caching only forGET
requests, and I would like to propose allowingPOST
requests as well.Use Case
In my setup, I use a Bastion Host to receive user requests and forward them to the actual server. To reduce unnecessary computations, I want to cache responses for
POST
requests when the same input is provided multiple times. There are cases where multiple identical requests are sent in a short period, and caching can help prevent redundant processing. However, since_uncachable
restricts caching toGET
requests, I am unable to achieve this with the current implementation.Allowing caching for POST requests could be useful when performing idempotent operations based on the user's request.
Proposed Change
I modified the code to allow caching for
POST
requests and confirmed that it works correctly. If there are no other logical issues, would it be possible to consider making this behavior configurable or allowing caching forPOST
requests under certain conditions?Looking forward to your thoughts. Thanks!