Cache Invalidation
Read caching is opt-in per query, and write invalidation is opt-in per write or per runtime configuration.
Distributed invalidation received from another instance clears local cache entries without publishing another invalidation. Locally initiated invalidation still publishes normally, so concurrent local writes and incoming messages are handled independently.
Default Behavior
Writes do not invalidate read caches by default:
This avoids unexpected broad cache deletes on write-heavy systems.
Per-Write Precise Invalidation
Use cache.invalidate when a write is known to affect a cached read:
Supported descriptor operations: find, findOne, count, findPage, aggregate, distinct, findOneById, and findByIds.
For aggregate write pipelines ($merge / $out), descriptor invalidation is resolved against the write target collection.
Per-Write No-Op Override
cache.invalidate: false and cache.invalidate: [] mean "do not invalidate anything for this write". They override instance-level cache.autoInvalidate: true:
Broad Invalidation
Use broad invalidation when the write can affect many cached reads:
Or enable it globally:
Global broad invalidation is convenient but can increase cache delete volume, Redis Pub/Sub traffic, and cache refill pressure.
Manual Invalidation
Use collection.invalidate() after native driver writes, external jobs, or maintenance scripts:
invalidate() clears collection read-cache patterns. It does not make MongoDB writes and cache invalidation atomic.