long2ice / fastapi-cache

fastapi-cache is a tool to cache fastapi response and function result, with backends support redis and memcached.
https://github.com/long2ice/fastapi-cache
Apache License 2.0
1.38k stars 167 forks source link

Not cached with postman #352

Open mfroger opened 11 months ago

mfroger commented 11 months ago

Hi all,

My cache system is working on browser but not in postman

@app.get("/", include_in_schema=False) @cache(expire=600) async def app_home(request: Request): return {'Domain : %s' % generate_random(20)}

Do you have an idea ?

Sajadrahimi commented 11 months ago

Postman sends no-cache header by default which is not necessarily set on your browser, that is why the response is cached on your browser and not on the postman. You can remove this header in the settings.

You can also remove this check from the cache decorator and write your own to make it work with your needs:

request.headers.get("Cache-Control") in ("no-store", "no-cache")

Bharat23 commented 10 months ago

To add to @Sajadrahimi's comment. Another way you can disable Cache-Control: no-cache set by postman is by simply sending a dummy header eg:

Cache-Control: <some invalid value>

I recommend labeling it as a question and closing this one as it has been answered.