[Python Tips] Expiring Dict
Expiring Dict
Expiring dict is a very useful library for caching data via ordered dictionaries. It works similar to a regular dictionary but will cache data for a short period of time. It can be used as a simple caching layer where you don't want to get into something like Redis.
Installation
pip install expiringdict
Using expiring dict
Creating expiring dict
from expiringdict import ExpiringDict
cache = ExpiringDict(max_length=50, max_age_seconds=60)
This will create an expiring dict that contains a max of 50 elements and expires in 60 seconds.
Add data
cache["follows"] = "35"
Retrieve data
cache.get("key")
Summary
Expiring dict is an easy to use library that can give you a quick and easy tool for caching data for short periods of time. If you need more complex caching, you will want to look at a full framework like Redis. Expiring dict has support for Redis directly.
My Python Tips Series
Leave [Python Tips] Expiring Dict to:
Read more #programming posts
Best Posts From Marky
We have not curated any of themarkymark's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Marky
- Tan Stack Scanner
- New LLM benchmark: llmtester
- Receive proactive alerts when your openclaw instance is unavailable
- My two favorite Openclaw hacks
- If you are running openclaw, make sure you are updated.
- Some things I wish someone told me when I setup Openclaw
- If you are running openclaw, make sure you are updated.
- Hive Hot or Not improvements
- Hive Hot or Not!
- Block Bandits update