long2ice/fastapi-cache

Not cached with postman

mfroger opened this issue · 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 ?

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

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.