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

[Question] Method post is caching?

Open victorparra96 opened this issue 2 years ago • 2 comments

I try cache for fastapi but i not know if post method is caching, or is only for get method

victorparra96 avatar Mar 30 '22 15:03 victorparra96

Just for get, reference http protocol

long2ice avatar Mar 30 '22 15:03 long2ice

@victorparra96 you can modify the decorator like this to enable caching for POST https://github.com/long2ice/fastapi-cache/blob/master/fastapi_cache/decorator.py#L53

if request.method not in {"GET", "POST"}:
    return await func(request, *args, **kwargs)

I haven't personally experimented this with this library, but I have done this with https://github.com/a-luna/fastapi-redis-cache

kishvanchee avatar May 03 '22 11:05 kishvanchee

Can we move this into the main branch? Definitely seems useful.

aiwhoo avatar Oct 27 '22 23:10 aiwhoo

agreed, would definitely find this useful

gegnew avatar Nov 10 '22 22:11 gegnew

@long2ice I believe that caching POST requests or any request method can be done because we can leverage the key_builder parameter. What do you think, if it's possible, I would like to submit a pull request for it.

mkdir700 avatar Jan 15 '23 12:01 mkdir700

We should probably consolidate this into a single issue. I've commented on #75, which is the same issue.

mjpieters avatar May 12 '23 18:05 mjpieters