A chain of transformations is a recipe, and every action cooks it again — unless the result is deliberately held. Holding it is persistence: Spark keeps the computed partitions, in memory, on disk, or in a combination, so that later actions read the held result instead of re-cooking the chain beneath it.

The engine offers a family of choices for how to hold data, called storage levels. They span memory-only, disk-only, memory with disk overflow, and replicated variants. The menu matters less than the judgment that governs every item on it: a cache is a purchase.

You pay for it in storage memory, in the time and movement of computing and placing it, and in the risk that it evicts or spills something else. You are repaid only if the held data is actually re-read, by later actions or later steps, often enough that the re-reads' savings exceed the purchase. A cache that is read once more, cheaply, or never, is not an optimization. It is rent.

The practitioner's test is three questions, in order

First: will it be re-read? Name the consumers — the specific later actions or steps that will read the held result — and count them. "Probably useful" is not a consumer.

Second: is re-cooking actually expensive? A held result saves the cost of the chain beneath it. If that chain is a narrow read-and-filter of modest data, re-cooking is cheap and the cache buys little. A chain containing a wide shuffle or an expensive join repays holding handsomely. Cache the expensive, not the convenient.

Third: what does holding displace? Sum the held bytes into the storage ledger, at the moment of peak execution, and state what execution will spill, or what other storage will be evicted, if the sums collide.

A cache decision that cannot answer all three is a reflex. And reflexes are how dead caches are born: held, never read, quietly taxing every run.

Used twice is not the test

The familiar rule of thumb says to cache anything used more than once, because memory is there to be used.

Memory is there to be allocated, and every byte held for one dataset is a byte denied to execution working room and to every other held dataset. The question is never whether the data is used twice. It is whether the re-cooking saved exceeds the holding's full price — storage pressure, placement cost, and eviction risk — for this data, at this size, under this run's other demands.

A dataset read twice, where the chain beneath it is a cheap filter, fails that test: the second cooking costs little, and the holding costs room the run needed elsewhere. A dataset read twice, where the chain beneath it contains an expensive join, passes easily. The count of re-reads is one fact in the decision. It was never the decision itself.

Holding in memory and writing to storage answer different questions

One neighboring decision deserves its own attention, because teams confuse the two constantly: holding in memory versus writing the intermediate to storage and reading it back.

The written intermediate survives the job that made it. It can serve other jobs and other days, and it pays its price in storage operations rather than in the storage pile of a running executor — it does not compete with execution at all. The held cache is faster, and dies with the application.

When the consumers are inside one run and the chain beneath is expensive, hold. When the consumers are tomorrow's jobs, or the intermediate is a contract other teams depend on, write it — deliberately, in a sound layout — and let the cache question rest.

Estates get into trouble when a cache is asked to do a written dataset's job, outliving its application in nobody's design, or when a dataset is written nightly to serve consumers who all live inside a single run and could have read a holding at a fraction of the cost. The two mechanisms are not rivals. They are answers to two different questions about who consumes, and when.

Two disciplines keep caches honest over time

First, release deliberately. Held data should be unpersisted when its last named consumer has passed, not left to be evicted by pressure at some other operation's moment of need. An estate whose caches are all eventually evicted by strangers is an estate nobody is managing.

Second, re-audit the premise. The consumers that justified a cache get refactored away. The expensive chain gets optimized until re-cooking is cheap. The data shrinks. And the cache stands on, billing every run for a saving that no longer exists.

The cache ledger — what is held, why, its named consumers, its size in the storage pile — belongs in the job's review documents beside the join decisions, re-measured on the same schedule, for the same reason: size facts and consumer facts rot, and every standing optimization is a claim about facts.

So ask the three questions, in writing, before you hold anything. Name the consumers and count them. Price the re-cooking you are actually avoiding. State what the holding displaces at peak. If the answers hold up, cache with confidence. If they do not, let the recipe cook again — and spend the memory on the work that needs it.

Experience it, don’t just read about it

Caching is a purchase repaid only when named consumers re-read held data enough to beat the full cost of holding it is Concept 10 of Apache Spark in Practice (Course No. 568), from Cognosco Learning, a learning company powered by AI. The course builds Spark practice beyond this distinction — Memory in Three Piles, Joins by Cost, Not by Habit, and The UI as Evidence — each worked through with an Agentic Socratic AI coach, one learner at a time. Try a Free Preview at cognoscolearning.com.

Try a Free PreviewAll Signature CoursesThe Corporate License

Navigate your own course.

← All Insights

© 2026 Cognosco Learning. All rights reserved.