Simple lru_cache for asyncio
Project description
- 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
Project details
Release history Release notifications | RSS feed
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.1.0.tar.gz
(4.7 kB
view details)
File details
Details for the file async_lru-0.1.0.tar.gz.
File metadata
- Download URL: async_lru-0.1.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b11c5a5d9e238a11c8e908989bb23bb09472acf5c927f0b868925d9ff1b3e6c
|
|
| MD5 |
1c3a394aacae4caec72c3b1018ea35b4
|
|
| BLAKE2b-256 |
5c24c2a4ab97f70ba01272c270ff44a72b8aac989752537bebd8e641a9fafa11
|