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.1.tar.gz
(3.2 kB
view hashes)
Built Distribution
Close
Hashes for expiring_dict-1.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5387bfc1cac9b4e78d37ab787a438ca29e20c6d360a230ed3ce8cfca088d53f |
|
MD5 | 822f81401e5d015a0587ff3b98f2a879 |
|
BLAKE2b-256 | 00bbeb786bb0cbc257d9cba8bb0737223ffce336fa9b3e9ab6ddc6b337b0d6ba |