Skip to main content

Python dict with TTL support for auto-expiring caches

Project description

py-expiring-dict

Python dict with TTL support for auto-expiring caches

Install

pip install expiring-dict

Usage

Class Level TTL

from time import sleep
from expiring_dict import ExpiringDict

cache = ExpiringDict(1)  # Keys will exist for 1 second

cache["abc123"] = "some value"
assert "abc123" in cache
sleep(1)
assert "abc123" not in cache

Key Level TTL

from time import sleep
from expiring_dict import ExpiringDict

cache = ExpiringDict()  # No TTL set, keys set via [] will not expire

cache["abc"] = "persistent"
cache.ttl("123", "expired", 1)  # This will expire after 1 second
assert "abc" in cache
assert "123" in cache
sleep(1)
assert "abc" in cache
assert "123" not in cache

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

expiring_dict-1.1.2.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

expiring_dict-1.1.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file expiring_dict-1.1.2.tar.gz.

File metadata

  • Download URL: expiring_dict-1.1.2.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.20

File hashes

Hashes for expiring_dict-1.1.2.tar.gz
Algorithm Hash digest
SHA256 ca8cb802304eae5b33a23ec4c19019b610adfda50cbc4c9bfa3ad5c2cd387631
MD5 8f368aae147fd33090e21d7e9fb0dc13
BLAKE2b-256 2f127e71bb6aaf95e1e27994bfb87d0b8e73b0e4cfcfa64b611abd5088c7ac99

See more details on using hashes here.

File details

Details for the file expiring_dict-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: expiring_dict-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.20

File hashes

Hashes for expiring_dict-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fe5ac10c1e985edfba5f90666cf52ad295a93b4521f20dabcd769a9372d70905
MD5 c6edd80f4916e527d39c58021f7db9fa
BLAKE2b-256 15f7be98b00881a13982675626ed20323ce276358b0d6bf9b370b030c6f6b22f

See more details on using hashes here.

Supported by

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