liveBook · Manning

Materialized.withCachingDisabled()

As explained in Kafka Streams in Action, Second Edition

Materialized.withCachingDisabled() is a Kafka Streams configuration method that disables caching for an individual materialized state store.

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
figure

Use the figure to visualize how caching suppresses intermediate aggregation results and releases the latest update during a cache flush. section 7.2.1

How Kafka Streams in Action, Second Edition covers it

How deep it goes
Explains selective and global cache disablement, observable updates, and increased state-store and changelog writes.
Examples
Uses a counting state store and a figure showing cached intermediate aggregation results.
What it assumes
Assumes familiarity with Kafka Streams stateful operations, materialized state stores, and changelog topics.
What you can do after
Apply it via the Materialized API to expose every update from one stateful operation without changing other stores.
How it connects
Connects Materialized configuration with state stores, stateful operations, aggregation, changelog topics, and Kafka Streams caching.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kafka Streams in Action, Second Edition. The section links point to the parts of the book it draws on.