CachedResponseMixin renders every cached response twice
It seems to me that _store_api_response() in api/mixins.py renders the response twice on every cache miss: once when response.render() is called and once when response.rendered_content is accessed. Can anyone confirm this?
Confirmed. In DRF, Response.rendered_content is an uncached property — it runs the accepted renderer on every access — and Response.render() itself does self.content = self.rendered_content. So on a cache miss, _store_api_response() renders once inside render() and a second time when it reads rendered_content for the cache payload.
I verified with a counting renderer wrapping JSONRenderer: the current path executes the renderer 2 times; reading response.content (the bytes render() already stored) executes it 1 time and caches the identical payload. So the fix is one line: cache response.content instead of response.rendered_content.
Happy to take this on and put up a small PR if you assign me.
Thanks @ABHIGYA0205 ! I'll assign you! :)