Skip to main content

TTL memoization for sync/async functions with stampede protection

Project description

cachememo

Tiny, safe memoization for Python - with TTL and async support.

cachememo helps you cache the results of expensive functions without accidentally shooting yourself in the foot under concurrency.

It’s designed for when:

  • you need time-based expiration (TTL)
  • you are working with async functions
  • you want to avoid cache stampedes under load

Installation

pip install cachememo

Basic Usage

from cachememo import memoize

@memoize(ttl=60)
def expensive(x: int) -> int:
    return x * 2

@memoize(ttl=30)
async def fetch_user(uid: str) -> dict:
    ...

License

MIT

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

cachememo-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cachememo-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file cachememo-0.1.0.tar.gz.

File metadata

  • Download URL: cachememo-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for cachememo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 dcf81d89402551c77b9f7118ef3b224e07acd4d34a6e4bf33ed8cb58db5cf1ba
MD5 f20436001f18fc5e73d7493ea906efc5
BLAKE2b-256 4851c65b840bf70eef0c066c54f83b1aa98ecbad9fdc0268fad07debc3b8f48d

See more details on using hashes here.

File details

Details for the file cachememo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cachememo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for cachememo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cee00d60bd7fb4b37db8e7fb69c6faec7f5e8622a82e0399d5868cb84a32a78a
MD5 ccfd24d152434c52b9ff0502bd6c68d7
BLAKE2b-256 890b3b3bf856224ae3c578b7420df130172a4edb4cf9707f9d63a57343db9f40

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