For example, how would
x.foreach(rdd => rdd.cache())
be different from
x.foreachRDD(rdd => rdd.cache())
Note that x is a DStream here.
x
DStream
There is no difference in work, foreach() uses foreachRDD. foreach() was deprecated and in Spark 2.0 this function is removed