public long size() {
        long size = 0;
        for (final NamedCache cache : caches.values()) {
            size += cache.size();
            if (isOverflowing(size)) {
                return Long.MAX_VALUE;
            }
        }
        return size;
    }
Add a listener that is called each time an entry is evicted from the cache or an explicit flush is called
streams/src/main/java/org/apache/kafka/streams/state/internals/ThreadCache.java