Apache Spark Big Data (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
What is the difference between `cache()` and `persist()`?
senior LevelMost AskedSystem Design
In Simple Words:
cache(): Shortcut forpersist(StorageLevel.MEMORY_AND_DISK)(in DataFrames) orMEMORY_ONLY(in RDDs).persist(level): Allows explicitly specifying the storage level:MEMORY_ONLY: Deserialized in RAM (fastest, high RAM usage).MEMORY_ONLY_SER: Serialized in RAM (saves 60% memory, slight CPU deserialize cost).MEMORY_AND_DISK: Spills to local disk when RAM is full.DISK_ONLY: Stored purely on local disk.