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.3k stars 160 forks source link

clearing cache not having effect as max-age directive is making browser not connectin to the server to check the if cache is valid #423

Open IOR88 opened 5 months ago

IOR88 commented 5 months ago

I think the end part of the code is making the browser to not refresh the cache, I saw discussions about it in the forum but not sure how we could change it, as I think this logic maybe different on per view basis ? I have one api for which I need to clear cache when other apis are triggered to refresh information, in that case I cannot pass max-age, I should pass no-cache, as other way browser is not verifying if cache is valid.

            # response.headers["Cache-Control"] = f"max-age={expire}"
            etag = f"W/{hash(encoded_ret)}"
            response.headers["ETag"] = etag
            return ret