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

Uploaded Source

Built Distribution

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

expiring_dict-1.0.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file expiring-dict-1.0.0.tar.gz.

File metadata

  • Download URL: expiring-dict-1.0.0.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for expiring-dict-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9598f44540da7da31704fdc1fa46dcfd5c8143eec0d3cc53b030e8b05ce75fd8
MD5 c4eec2993da36c8b9bd69dc0decacd83
BLAKE2b-256 261da694ed2321cc8c3f3a6c56698f39cde16341d82191887ff2939875efef37

See more details on using hashes here.

File details

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

File metadata

  • Download URL: expiring_dict-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

File hashes

Hashes for expiring_dict-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f11568c1e95ad28f9a927d1b0bc049efc1cd40782f67d1b9ef69b77cd838c266
MD5 66fb3cfb1efe1b72582e12f5d653eb76
BLAKE2b-256 485b9f98387f6494510d37fc1990ca6639b7f18cd6772382b4507375259d2bf2

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