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

Not cached with postman

Open mfroger opened this issue 1 year ago • 2 comments

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 ?

mfroger avatar Dec 06 '23 11:12 mfroger

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")

Sajadrahimi avatar Dec 16 '23 12:12 Sajadrahimi

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.

Bharat23 avatar Jan 10 '24 04:01 Bharat23