HomeInterview QuestionsHow do Spark's cache and persist operations work? …

How do Spark's cache and persist operations work? Would you classify them as actions or transformations?

🟡 Medium Conceptual Junior level
1Times asked
Aug 2026Last seen
Aug 2026First seen

💡 Model Answer

cache() is a shorthand for persist(StorageLevel.MEMORY_ONLY). Both methods are lazy transformations that tag an RDD/DataFrame to be stored in the specified storage level. They return the same logical plan but with a persistence flag. The actual materialization happens when an action (e.g., count, collect) forces the RDD to be computed. Therefore, cache() and persist() are considered transformations, not actions.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500