A simple Python dict with TTL support for auto-expiring caches with support for case-insensitive keys.
pip install expiring-cache
- TTL support for auto-caching
- Case-insensitive keys support
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