- 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.3.tar.gz
(4.1 kB
view details)
File details
Details for the file async_lru-0.0.3.tar.gz.
File metadata
- Download URL: async_lru-0.0.3.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36f00c62fde2dc2601a9fa562e133f81c505adc00d63745d8b8cc4f0e60d0714
|
|
| MD5 |
1744953cf0f995680b335a349cb9d6d3
|
|
| BLAKE2b-256 |
50f5be77e764839756dbf11aa42162b82e82ec50e16caed7e5b2f9470efef578
|