How to cache `StreamingResponse`?
See original GitHub issueHi, is there a way to cache StreamingResponse?
Currently i get:
ValueError: [TypeError("'async_generator' object is not iterable"), TypeError('vars() argument must have __dict__ attribute')]
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
How to cache StreamReponse or make a cache middleware
I'd like to make a general cache middleware and wrote code above. ... So it's basically fine to read data from StreamingResponse.
Read more >How to cache StreamingResponse? - python - Stack Overflow
I tried aiocache package and fastapi-cache package, but all this kind of packages try to convert value being cached to JSON or even...
Read more >Custom Response - HTML, Stream, File, others - FastAPI
Using StreamingResponse with file-like objects¶. If you have a file-like object (e.g. the object returned by open() ), you can create a generator...
Read more >Received & return a file from in-memory buffer using FastAPI
The right way of sending a file from memory is by using StreamingResponse , but StreamingResponse requires an iterator object, e.g.. from ...
Read more >Responses - Starlette
Takes an async generator or a normal generator/iterator and streams the response body. from starlette.responses import StreamingResponse import asyncio async ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can draft a solution via subclassing StreamingResponse (I think it will be less error-prone). Regarding the finiteness of the iterator, I can try adding both time and size constraints.
I also think, that overwritting ‘stream_response’ would be better solution.