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.0.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.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: expiring-dict-1.1.0.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.7.7

File hashes

Hashes for expiring-dict-1.1.0.tar.gz
Algorithm Hash digest
SHA256 3c404adb1e4369468cb7e51bfbc9c470d7e2e863efe2a1c75d4ed706d0dce1a6
MD5 ce5fce352fb264e15291bd6d53e10693
BLAKE2b-256 9301001f5c96605925c7014f80c3624709cff460f65626c6596ae984debd98c4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: expiring_dict-1.1.0-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.7.7

File hashes

Hashes for expiring_dict-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 586f6c5c0e5f111d5237f3fffcdefcfa813fb1e4340f9e3ef819bc70d3cc36cb
MD5 df21cd7537eeb64789c6c65e270baead
BLAKE2b-256 e5e9bfed06c7f956d43cbca465524085d137869c508d040963bd033215bbfc4b

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