Как кэшировать сопрограммы asyncio ⇐ Python
-
Anonymous
Как кэшировать сопрограммы asyncio
I am using aiohttp to make a simple HTTP request in python 3.4 like this:
response = yield from aiohttp.get(url) The application requests the same URL over and over again so naturally I wanted to cache it. My first attempt was something like this:
@functools.lru_cache(maxsize=128) def cached_request(url): return aiohttp.get(url) The first call to cached_request works fine, but in later calls I end up with None instead of the response object.
I am rather new to asyncio so I tried a lot of combinations of the asyncio.coroutine decorator, yield from and some other things, but none seemed to work.
So how does caching coroutines work?
Источник: https://stackoverflow.com/questions/341 ... coroutines
I am using aiohttp to make a simple HTTP request in python 3.4 like this:
response = yield from aiohttp.get(url) The application requests the same URL over and over again so naturally I wanted to cache it. My first attempt was something like this:
@functools.lru_cache(maxsize=128) def cached_request(url): return aiohttp.get(url) The first call to cached_request works fine, but in later calls I end up with None instead of the response object.
I am rather new to asyncio so I tried a lot of combinations of the asyncio.coroutine decorator, yield from and some other things, but none seemed to work.
So how does caching coroutines work?
Источник: https://stackoverflow.com/questions/341 ... coroutines