Skip to main content

Simple lru_cache for asyncio

Project description

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

Project details


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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for async_lru-0.0.5.tar.gz
Algorithm Hash digest
SHA256 9eecba6c248bae72f8dffed87ec12ee3838d008829406bc3b4486bef1e00a644
MD5 e2d0ae5b4ea0f9fd71ca84f05c834275
BLAKE2b-256 372ee4050eae2761f59ae4b08c02aced0e74daf903774cd07cfab1a0f2080631

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