skillfed

py-memoize

Caching library for asynchronous Python applications (both based on asyncio and Tornado) that handles dogpiling properly and provides a configurable & extensible API.

py-memoize v3.1.1 182.6K downloads/30d#10,093 on PyPI74
Permissive license Apache License 2.0 DORMANT released

What it is and what it does

py-memoize is a caching library designed specifically for asynchronous Python code—both asyncio and Tornado—that solves the cache stampede (dog-piling) problem where multiple concurrent tasks simultaneously miss the cache and flood the underlying resource. It wraps expensive async functions with a decorator to cache and reuse their results, and includes built-in protections against concurrent cache misses.

The library is highly configurable: you can tune cache timeouts, key generation strategies, storage backends, eviction policies (least-recently-updated by default), and value post-processing (including optional deep-copy). It supports background cache refreshing with separate update and expiration delays, allowing stale values to be refreshed asynchronously without observable latency. All components are extensible, so you can plug in custom storage, key extraction, or eviction logic.

Use it for:

  • Memoize expensive async API calls or database queries in asyncio services to reduce latency and backend load
  • Prevent cache stampede in high-concurrency async applications where multiple tasks would otherwise recompute the same result simultaneously
  • Cache results with tunable background refresh to serve stale data while updating in the background, avoiding request latency spikes
  • Implement custom cache storage (e.g., Redis, Memcached) by extending the provided storage and serialization interfaces
  • Decorate Tornado async handlers to cache computed responses across concurrent requests

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Caching library for async Python applications that prevents cache stampede (dog-piling) and provides a configurable, extensible API for memoizing expensive async function calls.

Yes, if you are building async Python services and need protection against cache stampede. The library is stable and has no known vulnerabilities, but note that maintenance is dormant (676 days since last release)—verify compatibility with your target Python version and async framework before adopting. For simple in-memory caching in active projects, consider whether the dormancy risk is acceptable.

Install

py-memoize on PyPI

pip

pip install py-memoize

uv

uv add py-memoize

poetry

poetry add py-memoize

Installing py-memoize

Before you install

Installs with no runtime dependencies. Maintenance is dormant—last release was 676 days ago (2024-10-07), though the repository remains active with 74 stars and no archived status.

License in practice

Licensed under Apache License 2.0 (permissive), allowing commercial and private use with minimal restrictions.

Quickstart

pip install py-memoize

import asyncio
from memoize.wrapper import memoize

@memoize()
async def expensive_computation():
    return 'result'

asyncio.run(expensive_computation())

Verify before relying

  • Whether the dormant maintenance status (676 days since last release) affects compatibility with current Python async ecosystems
  • Real-world performance impact of deep-copy post-processing on large cached objects
  • Whether ujson extra dependency improves JSON serialization performance meaningfully

Package facts

License Apache License 2.0 (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance dormant — 676 days since the last release
Last repo commit
First released
Downloads 182,579/month — #10,093 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: py_memoize-3.1.1-py3-none-any.whl

Keywords: python, cache, tornado, asyncio

Framework :: AsyncIOIntended Audience :: DevelopersProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries

Tags

asyncio caching decoratorasync function memoizationcache stampede preventiondog-piling proof cacheasync result cachingconfigurable async cachetornado asyncio cache
asynciocache-stampedememoization

More Libraries packages