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.2.tar.gz (6.8 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for expiringdict-1.1.2.tar.gz
Algorithm Hash digest
SHA256 b4616606b909c570e7f69a882637ad59d34b8a1f50d64453c562f4fa96e3b300
MD5 07b0aefdc437280b036f554ef60eeec8
BLAKE2b-256 7c0b1d683fbc830023fff847f44ff43adcd2c93f9b53886b64f7fd110200adfc

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