client-query-cache¶
Cache repeated PyMongo queries in your application, with synchronous and asyncio APIs. MongoDB change streams invalidate affected results when data changes, including writes by other clients.
For multiple trusted workers on one host, a Rust-backed native shared cache lets processes reuse the same cached documents and one change stream per active database. Workers avoid storing their own copies of the hot data. Process-local and shared managers cache the same six PyMongo read methods, including find, aggregate and counts; shared reads add eligibility restrictions. The manager comparison covers the differences.
Sharing has an owner process and admission costs. The measured comparisons show hot-read benefits and cold-read costs; neither Rust nor sharing guarantees a win for every workload.
Install and start¶
- Check whether caching fits your consistency and workload needs.
- Choose a manager for independent process-local caching or shared reads across workers.
- Check the requirements and install.
- Follow the synchronous or asyncio quick start, or run the shared FastAPI application.
Before using cached reads, review the consistency guarantees and plan direct PyMongo reads where freshness is required.
For hypothetical travel, retail, logistics, and reporting workflows, read Use cases.
Operate the application¶
- Cached reads and eligibility explain which requests can hit.
- Deployment covers ownership, memory, security and recovery for both managers.
- Monitoring explains the diagnostics available in each mode.
- API reference gives exact call and configuration contracts.
- Examples provide runnable web applications and adapters.