title: How to enable caching on in-memory Kafka Streams state store
body: <p>I want to decrease the number of data being sent downstream, and since I only care about the last value of a given key, I'm reading data from a topic this way:</p>
  
  <pre><code>KTable table = build.table("inputTopic", Materialized.as("myStore"));
  </code></pre>
  
  <p>Why? Because under the hood, the data is being cached, as described <a href="https://cwiki.apache.org/confluence/display/KAFKA/KIP-63%3A+Unify+store+and+downstream+caching+in+streams" rel="nofollow noreferrer">here</a>, and forwarded only if the <em>commit.interval.ms</em> or <em>cache.max.bytes.buffering</em> kicks in.</p>
  
  <p>So far so good, but since in this case I'm not taking advantage of RocksDB at all, so I'd like to replace it with the default implementation of an in-memory store. I implicitly enable caching, just in case.</p>
  
  <pre><code>Materialized.as(Stores.inMemoryKeyValueStore("myStore")).withCachingEnabled();
  </code></pre>
  
  <p>It doesn't work, though - the data is not being cached and every record is being sent downstream.</p>
  
  <p>Is there another way to enable caching? Or perhaps there a better way to do what I'm trying to achieve?</p>