Skip to main content
info:

Simple lru cache for asyncio

https://img.shields.io/travis/wikibusiness/async_lru.svg https://img.shields.io/pypi/v/async_lru.svg

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.2.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file async_lru-0.0.2.tar.gz.

File metadata

  • Download URL: async_lru-0.0.2.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for async_lru-0.0.2.tar.gz
Algorithm Hash digest
SHA256 b381b1bf703e69ede11b2af9b183ebb9747f9d3f89951d3daaacd796f8c1413f
MD5 5b8274bc5a66cc99b4e48bd85b6bf1a0
BLAKE2b-256 ffe0b085a0d88a5a301d59eac982e528a141b2bacae1aedec53e9f8587c8160a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page