Skip to main content

A simple Python dict with TTL support for auto-expiring caches with support for case-insensitive keys.

Project description

expiring-cache

A simple Python dict with TTL support for auto-expiring caches with support for case-insensitive keys.

Installation

pip install expiring-cache

Features

  • TTL support for auto-caching
  • Case-insensitive keys support

Usage

Example 1:

import time
from cache import ExpiringCache

cache = ExpiringCache(2) # Keys will exist for 2 seconds.

cache['ABC'] = 'Example value'
print(cache['ABC']) # Prints the 'Example Value'
time.sleep(2)
print(cache['ABC']) # Raises KeyError

Example 2: (shows case-insensitive feature)

import time
from cache import ExpiringCache

cache = ExpiringCache(2, case_insensitive=True)

cache['ABC'] = 'Example value'
print(cache['ABC'])
print(cache['abc'])
# Both print statements above print the exact same 'Example Value'

time.sleep(2)
print(cache['ABC'])
print(cache['abc'])
# Both the print statements above raise KeyError

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-cache-1.0.0.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

expiring_cache-1.0.0-py3-none-any.whl (4.4 kB view hashes)

Uploaded Python 3

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