Skip to main content

Dictionary with auto-expiring values for caching purposes

Project description

expiringdict

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!

Installation

If you wish to install from PyPi:

pip install expiringdict

If you wish to download the source and install from GitHub:

git clone git@github.com:mailgun/expiringdict.git
python setup.py install

or to install with test dependencies (Nose, Mock, coverage) run from the directory above:

pip install -e expiringdict[test]

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)

put and get a value there:

cache["key"] = "value"
cache.get("key")

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

expiringdict-1.1.3.tar.gz (6.8 kB view details)

Uploaded Source

File details

Details for the file expiringdict-1.1.3.tar.gz.

File metadata

File hashes

Hashes for expiringdict-1.1.3.tar.gz
Algorithm Hash digest
SHA256 08bebdc5e008085e0612bd141d62f837c3f80b8c1880a95e0863100757b55b08
MD5 094e1b6c57462abf73ae239780ec7593
BLAKE2b-256 0f19c726a028dd48261c5b3c16dab80f424e8904b8dc484a12d7c314e12d18c5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page