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(ttl=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-0.1.0.tar.gz (2.1 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-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: expiring-dict-0.1.0.tar.gz
  • Upload date:
  • Size: 2.1 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.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for expiring-dict-0.1.0.tar.gz
Algorithm Hash digest
SHA256 955aeaa5e9599da623e4ab381e95110f6afe50dff7ccd0677d4df0212c00cc94
MD5 073d6c425b315a8dd71c935576d11a8a
BLAKE2b-256 c0c868a3a78a7a0b8165349e6147a242e81f69d64e03bb2f049ce00ee39c20e4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: expiring_dict-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 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.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for expiring_dict-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2beeb246939dd848ad95fc21415108b5112171e561718973461960c89c821fc
MD5 323d1c1449e7e56f94e59777f165c2ba
BLAKE2b-256 47831cc803d52455391783333457864a2f6df2f5d4d4978c62a7ec80aeecd764

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