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.1.tar.gz (2.3 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.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: expiring-dict-1.0.1.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.9

File hashes

Hashes for expiring-dict-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cdc6336e57898fb45a62de98ec8b04a4352b631f25ebe80ea929ab744d6b2442
MD5 d9aa3ffcf954a3c5f9af160b6af60342
BLAKE2b-256 2241a2fd14b2643f969aaa6185cf32b2d46e7bd78f4f09d93c6872960f174098

See more details on using hashes here.

File details

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

File metadata

  • Download URL: expiring_dict-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.6.9

File hashes

Hashes for expiring_dict-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a5d153667ef0d0707a6c87fc0331f1c99973c7494cbd41228016381f0fc5b1ac
MD5 2b82e99992942b9789330d5d38ddb084
BLAKE2b-256 d3c3d08988745da244223b1e5b392b5e00bb2765ba0857b573eb191c69f416c6

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