fastapi-cache icon indicating copy to clipboard operation
fastapi-cache copied to clipboard

Do not make non-GET requests uncacheable

Open john-tipper opened this issue 2 years ago • 1 comments

I believe there's a use-case for allowing some non-GET requests to be cacheable.

Given restrictions on the length of HTTP requests, it is sometimes necessary to embed data into requests. Elasticsearch is an example that makes extensive use of GET requests using data, but this pattern is not possible with FastAPI because OpenAPI/Swagger does not support GET requests with embedded data.

As a result, if you want to use a FastAPI and have an endpoint that can accept large payloads (for example, because you want some sort of proxy in front of Elasticsearch, or a similar service) it is necessary to use a non-GET method, e.g. POST. However, fastapi-cache does not cache such queries.

I'd like to propose removing these two lines: https://github.com/long2ice/fastapi-cache/blob/main/fastapi_cache/decorator.py#L82-L83 so that it is up to the user of FastAPI to determine whether a method should be cached.

john-tipper avatar May 25 '23 17:05 john-tipper

That's OK, PR welcome.

long2ice avatar Jul 18 '23 06:07 long2ice