- info:
Simple lru cache for asyncio
Installation
pip install async_lru
Usage
import asyncio
import aiohttp
from async_lru import alru_cache
calls = 0
@alru_cache()
async def download(url):
global calls
calls += 1
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
return await response.text()
async def main():
coros = [
download('https://www.python.org/'),
download('https://www.python.org/'),
download('https://www.python.org/'),
download('https://www.python.org/'),
download('https://www.python.org/'),
download('https://www.python.org/'),
]
await asyncio.gather(*coros)
assert calls == 1
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
# closing is optional, but strictly recommended
loop.run_until_complete(download.close())
loop.close()
Python 3.3+ is required
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
async_lru-0.0.1.tar.gz
(3.3 kB
view details)
File details
Details for the file async_lru-0.0.1.tar.gz.
File metadata
- Download URL: async_lru-0.0.1.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5db10bd6342d5ba4d29704b1dbb5a5b77e04b2d548d783d1092a520a000aac7
|
|
| MD5 |
71a6c250624f2ef82f9e75f84178c39f
|
|
| BLAKE2b-256 |
af403c7e62490f07d55341c586652ac5b761704816ae7f776dd33210ca24a40e
|