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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for async_lru-0.0.6.tar.gz
Algorithm Hash digest
SHA256 396219bd9c5cd47c42cf48eb8f5c949660884638ab3419ecb171794b43d9bc17
MD5 701804e2b3f284f39043dcef0ddfe121
BLAKE2b-256 5a2f3342c29a9f03a3b11c1ad1522da5a8618553c45d25c544580be1a983d562

See more details on using hashes here.

Release history Release notifications | RSS feed

2.3.0

2 files

2.2.0

2 files

2.1.0

2 files

2.0.5

2 files

2.0.4

2 files

2.0.3

2 files

2.0.2

2 files

2.0.1

2 files

2.0.0

2 files

1.0.3

2 files

1.0.2

1 file

1.0.1

1 file

1.0.0

1 file

0.1.0

1 file

This release

0.0.6 This release

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page