Simple lru_cache for asyncio
Project description
- info:
Simple lru cache for asyncio
Installation
pip install async_lru
Usage
This package is 100% port of Python built-in function functools.lru_cache for asyncio
import asyncio
import aiohttp
from async_lru import alru_cache
@alru_cache(maxsize=32)
async def get_pep(num):
resource = 'http://www.python.org/dev/peps/pep-%04d/' % num
async with aiohttp.ClientSession() as session:
try:
async with session.get(resource) as s:
return await s.read()
except aiohttp.ClientError:
return 'Not Found'
async def main():
for n in 8, 290, 308, 320, 8, 218, 320, 279, 289, 320, 9991:
pep = await get_pep(n)
print(n, len(pep))
print(get_pep.cache_info())
# CacheInfo(hits=3, misses=8, maxsize=32, currsize=8)
# closing is optional, but highly recommended
await get_pep.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
Python 3.6+ is required
Thanks
The library was donated by Ocean S.A.
Thanks to the company for contribution.
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-1.0.3.tar.gz
(4.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file async-lru-1.0.3.tar.gz.
File metadata
- Download URL: async-lru-1.0.3.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2cb9b2915eb14e6cf3e717154b40f715bf90e596d73623677affd0d1fbcd32a
|
|
| MD5 |
4dfcb328f2e9a8fdc9cf78dfdb6d3eef
|
|
| BLAKE2b-256 |
fe674cb179c14ffa8b4a35fbe02255744bee4cbbaf61b35612c96ba4a618e4d5
|
File details
Details for the file async_lru-1.0.3-py3-none-any.whl.
File metadata
- Download URL: async_lru-1.0.3-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea692c303feb6211ff260d230dae1583636f13e05c9ae616eada77855b7f415c
|
|
| MD5 |
9490af19813c269787e8d97abafb06a9
|
|
| BLAKE2b-256 |
7e31a374a167be43c68e369ab954b4bf843f63484b6e1a739f90109a2d6864fb
|