Dictionary with auto-expiring values for caching purposes, support default value
Project description
Expiring Dict
expiringdict is a Python caching library. The core of the library is ExpiringDict class which is an ordered dictionary with auto-expiring values for caching purposes. Expiration happens on any access, object is locked during cleanup from expired values. ExpiringDict can not store more than max_len elements - the oldest will be deleted.
Note: Iteration over dict and also keys() do not remove expired values!
Features after fork
optioinal default value passed by dict after keys expired
Installation
If you wish to install from PyPi:
pip install expiringdict-with-default
If you wish to download the source and install from GitHub:
git clone git@github.com:weaming/expiringdict.git
python setup.py install
To run tests with coverage:
nosetests --with-coverage --cover-package=expiringdict
Usage
Create a dictionary with capacity for 100 elements and elements expiring in 10 seconds:
from expiringdict import ExpiringDict
cache = ExpiringDict(max_len=100, max_age_seconds=10, default={'name': 'Alice'})
put and get a value there:
cache["key"] = "value"
cache.get("key")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for expiringdict_with_default-1.1.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0de8e3158292fbab584f758f1b94fea34a764497d1c8dd807f7ad83c4e0d13f1 |
|
MD5 | 9a6fe5823b6ddc80ccf79359d6e09524 |
|
BLAKE2b-256 | 0a878e844ea799327c47706c17763bed4df77b4741bdf21a3fc89756c1aa5ec1 |
Hashes for expiringdict_with_default-1.1.7-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6222e846a341e699f7561adfd460598a92c873692fe0f5003767d67551f4b7cd |
|
MD5 | 52b39e0e69721316d61de09f7111d348 |
|
BLAKE2b-256 | b52f92a26b95d84454e647c550f7dbd5e75b8e918ee0f3c35af28f95f3e518a1 |