long2ice/fastapi-cache

Do not make non-GET requests uncacheable

Opened this issue · 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.

That's OK, PR welcome.