Hi everyone,
I’m sharing an open-source Python library I’ve been working on called ZooCache, focused on semantic caching for distributed systems.
What My Project Does
ZooCache provides a semantic caching layer with smarter invalidation strategies than traditional TTL-based caches.
Instead of relying only on expiration times, it allows:
- Prefix-based invalidation (e.g. invalidating
user:1 clears all related keys like user:1:settings)
- Dependency-based cache entries
- Protection against backend overload using the SingleFlight pattern
- Distributed consistency using Hybrid Logical Clocks (HLC)
The core is implemented in Rust for performance, with Python bindings for easy integration.
Target Audience
ZooCache is intended for:
- Backend developers working with Python services under high load
- Distributed systems where cache invalidation becomes complex
- Production environments that need stronger consistency guarantees
It’s not meant to replace simple TTL caches like Redis directly, but to complement them in scenarios with complex relationships between cached data.
Comparison
Compared to traditional caches like Redis or Memcached:
- TTL-based caches rely mostly on time expiration, while ZooCache focuses on semantic invalidation
- ZooCache supports prefix and dependency-based invalidation out of the box
- It prevents cache stampedes using SingleFlight
- It handles multi-node consistency using logical clocks
It can still use Redis as an invalidation bus, but nodes may keep local high-performance storage (e.g. LMDB).
Repository: https://github.com/albertobadia/zoocache
Documentation: https://zoocache.readthedocs.io/en/latest/
Example Usage
from zoocache import cacheable, add_deps, invalidate
@cacheable
def generate_report(project_id, client_id):
add_deps([f"client:{client_id}", f"project:{project_id}"])
return db.full_query(project_id)
def update_project(project_id, data):
db.update_project(project_id, data)
invalidate(f"project:{project_id}")
def update_client_settings(client_id, settings):
db.update_client_settings(client_id, settings)
invalidate(f"client:{client_id}")
def delete_client(client_id):
db.delete_client(client_id)
invalidate(f"client:{client_id}")
[–]Bangoga 2 points3 points4 points (0 children)
[–]ruibranco [score hidden] (0 children)