Skip to main content
InterviewHubPRO
Section Overview
Q16

Question 16 of 50

Part 2: Core Architecture & Implementation (Mid-Level)

32%
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 for persist(StorageLevel.MEMORY_AND_DISK) (in DataFrames) or MEMORY_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.