Skip to content

client-query-cache

Add an in-process read cache to an application using PyMongo directly. The library supports synchronous and asyncio clients and uses MongoDB change streams to invalidate cached results, without a separate cache server.

Install and start

Use Should you use this? to evaluate consistency, reuse, and deployment costs.

Start with installation, then follow the complete synchronous or asyncio tutorial.

Caching requires MongoDB 8.0+ on a replica set or sharded cluster. Writes go through PyMongo. Invalidation is asynchronous, so use direct reads wherever freshness is required; see consistency.

Find guidance

  • Usage: choose cached reads and understand raw fallback.
  • Benchmarks: evaluate your workload and inspect reproducible measurement evidence.
  • Examples: study and run applications and integrations with MongoDB-backed libraries.
  • API reference: exact options, limits, errors, and ownership contracts.
  • Operations: plan capacity, security, recovery, and monitoring.