Materialized.withCachingDisabled() disables Kafka Streams caching for one materialized state store. It is useful when an aggregation must expose every intermediate result instead of only the latest update after a cache flush. section 7.2.1
Choose the scope of cache control deliberately:
- Set StreamsConfig.CACHE_MAX_BYTES_BUFFERING_CONFIG to 0 to disable caching across every state store in the topology. section 7.2.1
- Call withCachingDisabled() on the Materialized object to disable caching for one stateful operation while leaving other stores unchanged. section 7.4.7
- Disabling caching makes every result observable but can increase writes to the state store and its changelog topic. section 7.2.1
Disable caching for a counting store
Apply the method while configuring the materialized store: count(Materialized.as("counting-store").withCachingDisabled()). This keeps cache behavior unchanged elsewhere while exposing each update from this stateful operation. section 7.2.1 section 7.4.7
Figure 7.3 Caching intermediate results of an aggregation operation
Use the figure to visualize how caching suppresses intermediate aggregation results and releases the latest update during a cache flush. section 7.2.1
