# 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](<https://alessio-locatelli.github.io/client-query-cache/stable/reference/shared-cache/index.md#worker-managers-and-reads>). The [manager comparison](<https://alessio-locatelli.github.io/client-query-cache/stable/getting-started/choose-a-manager/index.md>) covers the differences.

Sharing has an owner process and admission costs. The [measured comparisons](<https://alessio-locatelli.github.io/client-query-cache/stable/benchmarks/shared-cache/index.md>) show hot-read benefits and cold-read costs; neither Rust nor sharing guarantees a win for every workload.

## Install and start

1. [Check whether caching fits](<https://alessio-locatelli.github.io/client-query-cache/stable/getting-started/should-you-use-this/index.md>) your consistency and workload needs.
2. [Choose a manager](<https://alessio-locatelli.github.io/client-query-cache/stable/getting-started/choose-a-manager/index.md>) for independent process-local caching or shared reads across workers.
3. [Check the requirements and install](<https://alessio-locatelli.github.io/client-query-cache/stable/getting-started/installation/index.md>).
4. Follow the [synchronous](<https://alessio-locatelli.github.io/client-query-cache/stable/getting-started/synchronous/index.md>) or [asyncio](<https://alessio-locatelli.github.io/client-query-cache/stable/getting-started/asyncio/index.md>) quick start, or run the [shared FastAPI application](<https://alessio-locatelli.github.io/client-query-cache/stable/examples/fastapi-shared/index.md>).

Before using cached reads, review the [consistency guarantees](<https://alessio-locatelli.github.io/client-query-cache/stable/usage/consistency/index.md>) and plan direct PyMongo reads where freshness is required.

For hypothetical travel, retail, logistics, and reporting workflows, read [Use cases](<https://alessio-locatelli.github.io/client-query-cache/stable/use-cases/index.md>).

## Operate the application

- [Cached reads](<https://alessio-locatelli.github.io/client-query-cache/stable/usage/cached-reads/index.md>) and [eligibility](<https://alessio-locatelli.github.io/client-query-cache/stable/usage/eligibility/index.md>) explain which requests can hit.
- [Deployment](<https://alessio-locatelli.github.io/client-query-cache/stable/operations/index.md>) covers ownership, memory, security and recovery for both managers.
- [Monitoring](<https://alessio-locatelli.github.io/client-query-cache/stable/operations/monitoring/index.md>) explains the diagnostics available in each mode.
- [API reference](<https://alessio-locatelli.github.io/client-query-cache/stable/reference/api/index.md>) gives exact call and configuration contracts.
- [Examples](<https://alessio-locatelli.github.io/client-query-cache/stable/examples/index.md>) provide runnable web applications and adapters.
