What you will be able to do
- Explain how the disk cache speeds up repeated reads of Parquet and Delta Lake files by keeping local SSD copies on worker nodes
- Describe how the disk cache stays consistent after writes, and when its contents are evicted or lost
- Pick compute that has the disk cache enabled, and read or change its configuration
- Tell the disk cache apart from Spark cache()/persist and CACHE TABLE, and say when each one helps or hurts
Key concept
Disk cache — A Databricks feature, not part of the Delta Lake protocol. When a worker reads a remote Parquet file, including a file that backs a Delta table, it automatically keeps a copy on its own local storage. Later reads of that file on the same node come from local disk instead of cloud object storage.
1.How the disk cache turns remote reads into local reads
Reading a file from cloud object storage takes longer than reading it from a local disk. Without a cache, every query that touches the same Parquet files fetches them from S3 or ABFS again. A validation query followed by an aggregation over the same table pays for the remote fetch twice. Notebooks that run the same exploratory query ten times pay for it ten times.
The disk cache removes the repeated fetch. When a worker node pulls a Parquet data file from remote storage, it writes a copy to its own local storage in a fast intermediate format. If a later read on that node needs the same file, it reads the local copy, which is much faster. Nobody has to request this. The first read fills the cache, and that read is the only one that pays the remote cost. The cache works for all Parquet data files, and Delta Lake tables store their data as Parquet, so Delta reads benefit without any extra setup.
The cache holds file data, not answers. It stores copies of the remote files a query reads, so a different query over the same files also gets the speedup. It cannot store the results of arbitrary subqueries, and it never stands in for a query result. Returning a previous answer to a repeated statement is the job of a separate result cache in Databricks SQL. That cache stores query results and is invalidated when the underlying tables change.
The cache had two earlier names: the Delta cache and the DBIO cache. The name "Delta cache" led people to think the feature was part of the Delta Lake protocol, and Databricks renamed it to correct that. Disk caching is proprietary Databricks behaviour. Nothing about it is written into a table's transaction log, and an engine reading the same Delta table outside Databricks gets no benefit from it. Every node keeps its own cache on its own disks. A file cached on one cluster cannot be read by another cluster.
Checkpoint 1 of 7· Check yourself
On a Databricks cluster, a job runs a validation query against a Delta table and then an aggregation over the same Parquet files. An engine outside Databricks also reads that table from cloud storage. What does the disk cache do in this case?
The disk cache keeps copies of the file data on each worker's local storage, and the first read fills it automatically, so a different query over the same files on that node also gets the speedup. It is proprietary Databricks behaviour that is not written into the Delta protocol or the transaction log, so an external engine gets no benefit from it.
“Disk caching behavior is a proprietary Databricks feature. This name change seeks to resolve confusion that it was part of the Delta Lake protocol.”Source: docs.databricks.com
Checkpoint 2 of 7· Exam question
Which statement most accurately describes the disk cache feature on Databricks, formerly branded as the Delta cache?
Correct answer: A — It transparently copies remote data files, including Parquet files backing Delta tables, onto the local SSD of the worker node that reads them, so later queries can read from local disk instead of cloud storage.
- A. The disk cache is a Databricks Runtime compute-layer optimization, not part of the Delta transaction log, that copies remote Parquet data files onto local worker SSD storage on first read so subsequent reads of the same files avoid a round trip to cloud storage.
- B. The caching behavior lives in the Databricks Runtime's file-reading layer on the compute cluster, not in the Delta Lake open protocol or transaction log, so other engines reading the same Delta table do not automatically inherit this cache.
- C. There is no separate managed cache table created in Unity Catalog for this feature, and nothing requires an administrator to manually refresh it; the disk cache operates transparently on worker local storage and updates itself when source files change.
- D. The disk cache stores raw source file bytes rather than precomputed query results, and it is unrelated to materialized views, which are a separate feature that stores the output of a defined query rather than cached input files.
2.Staying consistent after writes, and losing the cache
The disk cache never serves stale data, and you do not have to invalidate it. It detects when data files are created, deleted, modified or overwritten, and it updates its contents to match. When a MERGE rewrites files, the old copies become stale entries, and the cache invalidates and evicts them on its own. You can run writes and reads against the same table on the same cluster without any cache management code.
Entries leave the cache in three ways. The least recently used files are evicted when space runs out. Any change to a file evicts that file's entry. A cluster restart clears everything. SQL warehouses work the same way: the disk cache has the same lifecycle as the local result cache. A warehouse that is stopped or restarted starts with an empty cache, and queries have to fill it again.
This lifecycle explains why the first query on a fresh cluster is always slower than the ones after it. Two settings should be tested separately. A cold run reads from remote storage. A warm run reads from local copies. If the cold run is the one that matters, for example a job that starts right after a cluster restart, you can prewarm the cache. Run specific queries over the hot tables first, so the data is local before the real workload starts.
The flag works like a switch on the read path. It does not delete anything. With the cache disabled, queries neither read from it nor add to it, and the files already written stay on local storage.
Checkpoint 3 of 7· Match them up
Match each event on a cluster using the disk cache to what happens to the cached data
Tap a term, then the definition that fits it.
The disk cache evicts entries in LRU order, detects changed files and drops them itself, and loses everything when the cluster restarts. That is why a cold run after a restart is slower unless the cache is prewarmed. You never need to refresh the cache by hand after an UPDATE or MERGE.
“Automatically in LRU fashion or on any file change, manually when restarting a cluster.”Source: docs.databricks.com
3.Which compute has the disk cache, and how to configure it
Whether a cluster uses the disk cache depends on its worker type. Databricks turns the cache on automatically for worker instance types that support it, so most of the configuration is done by choosing the node type. The recommended and simplest option is a worker type with SSD volumes. These cache-accelerated instances come with the cache enabled and tuned. On a node type that does not support disk caching, a repeated read gets no speedup: the second read goes back to cloud storage exactly like the first. A job that sometimes runs on such a node type is fast on some runs and slow on others.
On a supported worker, the cache uses at most half of the space on the local SSDs. You can change how much local storage it uses with Spark configuration set when you create the cluster. maxDiskUsage is the disk space per node reserved for cached data, in bytes. maxMetaDataCache is the disk space per node reserved for cached metadata. compression.enabled controls whether cached data is stored compressed.
spark.databricks.io.cache.maxDiskUsage 50g
spark.databricks.io.cache.maxMetaDataCache 1g
spark.databricks.io.cache.compression.enabled falseYou can check the current state from a notebook. The same key passed to spark.conf.set with true or false turns the cache on or off for the session.
spark.conf.get("spark.databricks.io.cache.enabled")Older code may use CACHE SELECT to load chosen columns or rows into the disk cache ahead of time. On SQL warehouses and on Databricks Runtime 14.2 and above, that command is ignored and an enhanced caching algorithm decides what to cache. The command does nothing, but it does not fail. The cache also helps with diagnosis. If a slow stage in the Spark UI shows a large Input column because it reads the same data several times, the disk cache is one of the listed fixes. The other read fixes include better data skipping and Photon. For more on reading stage I/O, see debugging with the Spark UI.
The run may have landed on an instance type without local SSD caching, so nothing was cached and both reads went to cloud storage. Or the cached files may have been evicted between the two reads. LRU eviction under space pressure, a write that changed the files, or a cluster restart would each force the second read back to remote storage.
Checkpoint 4 of 7· Check yourself
A team's iterative notebook queries re-read the same Delta tables, but every repeated read is as slow as the first. Which change does Databricks recommend so that the repeated reads come from local storage?
Databricks turns the disk cache on automatically only for worker types that support it, and the recommended setup is a worker type with SSD volumes. CACHE SELECT does nothing on DBR 14.2+. df.cache() is the Spark cache, which stores blocks of a DataFrame and does not make file copies. The disk cache is not a Delta table or protocol feature.
“The recommended (and easiest) way to use disk caching is to choose a worker type with SSD volumes when you configure your cluster.”Source: docs.databricks.com
Checkpoint 5 of 7· Exam question
A nightly job reads the same partition of a Delta table twice: once for a validation query and once, minutes later, for the main aggregation. The engineer expects the second read to be noticeably faster than the first because of the disk cache, but on some runs it is not. Which factor most likely explains the inconsistent speedup?
Correct answer: A — The job sometimes runs on instance types without local SSD storage, or on runs where the cache was already evicted, so the second read finds nothing cached and fetches the files from cloud storage again.
- A. The disk cache only helps when the reading node has local SSD storage and the relevant file blocks are still resident; on non-SSD instance types, or after eviction from limited disk space or a cluster restart between the two reads, the second read has to re-fetch from cloud storage exactly like the first.
- B. The transaction log determines which files are part of the current table version, but reading those files still goes through the disk cache when it is enabled; the log itself does not force every read to bypass local caching.
- C. Within a single nightly job it is common for both queries to run on the same cluster and therefore the same worker nodes, so this scenario does not describe an inherent architectural separation that would explain the inconsistency.
- D. The disk cache works for Parquet data files, which is the format underlying Delta Lake tables, so Delta table reads are exactly the kind of workload this feature is designed to accelerate, not one it excludes.
4.Disk cache versus Spark cache() and persist
Spark has its own caching API, and the two mechanisms are easy to mix up. They work at different levels. The disk cache copies raw Parquet file bytes, automatically, for any query that reads those files. df.cache(), df.persist(...) and CACHE TABLE keep the computed result of one DataFrame or query, stored as blocks whose location depends on the storage level. Spark caching only happens when code asks for it. Both are lazy: nothing is cached until data is actually read.
| Feature | Disk cache | Apache Spark cache |
|---|---|---|
| Stored as | Local files on a worker node | In-memory blocks, depending on storage level |
| Applied to | Any Parquet table stored on S3, ABFS and other file systems | Any DataFrame or RDD |
| Triggered | Automatically, on the first read (if the cache is enabled) | Manually, requires code changes |
| Evaluated | Lazily | Lazily |
| Availability | Enabled by default on certain node types; configuration flags turn it on or off | Always available |
| Evicted | LRU, on any file change, or when the cluster restarts | LRU, or manually with unpersist |
Spark caching can do some things the disk cache cannot. It can hold the output of any subquery, such as a costly join you plan to reuse three times. It can also hold data from formats other than Parquet, such as CSV, JSON and ORC. CACHE TABLE accepts a storage level such as DISK_ONLY or MEMORY_ONLY, and it uses MEMORY_AND_DISK when you do not set one. The cached data is shared across all Spark sessions on the cluster.
> CACHE TABLE testCache OPTIONS ('storageLevel' 'DISK_ONLY') SELECT * FROM testData;Spark caching also costs more than people expect. Cached blocks are held in memory, depending on the storage level, until they are evicted in LRU order or released with unpersist, so every cached result takes memory away from the queries that run alongside it. If the cache call sits in the wrong place in a query, it can fill all available memory and make queries much slower. On an autoscaling cluster, when a worker is decommissioned, the Spark cache on that worker is lost, and Spark has to reread the missing partitions from the source. CACHE TABLE is not compatible with the serverless compute architecture, where caching is tuned automatically. If you really need a result to persist, write it to a Delta table. As a general rule, Databricks recommends avoiding Spark caching, and using the disk cache for repeated reads of Parquet and Delta Lake data.
For a DataFrame built from a Delta table, then, calling df.cache() does not repeat what the disk cache already does. It is a separate, manual copy of one computed result, held in memory or on disk depending on the storage level, and released with unpersist. The disk cache, by contrast, already speeds up reads of the underlying files with no code at all. Spark caching only pays off when the expensive step is the computation rather than the file read, or when the source is not Parquet.
Checkpoint 6 of 7· Fill the gap
This statement keeps the computed result of a query in the Apache Spark cache rather than in the disk cache, and sets the storage level explicitly. Which keyword completes it?
> CACHE ? testCache OPTIONS ('storageLevel' 'DISK_ONLY') SELECT * FROM testData;CACHE TABLE stores a table's contents or a query's output in the Apache Spark cache, with a storage level you choose (MEMORY_AND_DISK if you set none). CACHE SELECT is the older command that loaded files into the disk cache, and it is ignored on SQL warehouses and on Databricks Runtime 14.2 and above. There is no CACHE DELTA command, because the disk cache is not a Delta Lake feature.
Source: docs.databricks.comCheckpoint 7 of 7· Exam question
A data engineer notices that several notebooks call df.cache() (or df.persist(StorageLevel.MEMORY_AND_DISK)) on a DataFrame built from a Delta table, expecting this to behave the same way as the cluster's disk cache. During code review, which statement correctly distinguishes the two mechanisms?
Correct answer: A — df.cache() is a manual Spark API that materializes one DataFrame's computed result in memory or on local disk for that session, while the disk cache automatically stores raw Parquet file bytes on worker local storage.
- A. Spark's
cache()/persist()is an explicit, DataFrame-scoped operation the developer must trigger and manage, storing a materialized query result. The disk cache instead runs automatically at the file-read layer, caching the raw Parquet bytes for any query that touches those files, regardless of which DataFrame issued the read. - B. The two mechanisms do not store the same thing: Spark's cache holds a materialized, possibly transformed DataFrame result, while the disk cache holds unmodified copies of source Parquet files, so calling
df.cache()is not simply a redundant duplicate of the disk cache. - C. Spark's
cache()/persist()API can spill to local disk depending on the storage level chosen, but it does not write into Unity Catalog managed storage, and it is tied to the active Spark session rather than surviving independently of it. - D. The disk cache activates automatically the first time a supported cluster reads a Parquet or Delta file; it needs no explicit caching call, and the legacy
CACHE SELECTstyle commands are unnecessary on clusters where automatic disk caching is enabled.
Sources
(5)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“it automatically stores a copy on its local storage in a fast intermediate format”
↩︎ How the disk cache turns remote reads into local reads“The cache works for all Parquet data files, including Delta Lake tables.”
↩︎ How the disk cache turns remote reads into local reads“Disk caching on Databricks was formerly referred to as the Delta cache and the DBIO cache.”
↩︎ How the disk cache turns remote reads into local reads“Any stale entries are automatically invalidated and evicted from the cache.”
↩︎ Staying consistent after writes, and losing the cache“Automatically in LRU fashion or on any file change, manually when restarting a cluster.”
↩︎ Staying consistent after writes, and losing the cache“Instead, it prevents queries from adding new data to the cache and reading data from the cache.”
↩︎ Staying consistent after writes, and losing the cache“The recommended (and easiest) way to use disk caching is to choose a worker type with SSD volumes when you configure your cluster.”
↩︎ Which compute has the disk cache, and how to configure it“The disk cache is configured to use at most half of the space available on the local SSDs provided with the worker nodes.”
↩︎ Which compute has the disk cache, and how to configure it“In SQL warehouses and Databricks Runtime 14.2 and above, the CACHE SELECT command is ignored.”
↩︎ Which compute has the disk cache, and how to configure it“In-memory blocks, but it depends on storage level.”
↩︎ Disk cache versus Spark cache() and persist“When a worker is decommissioned, the Spark cache stored on that worker is lost.”
↩︎ Disk cache versus Spark cache() and persist“it automatically stores a copy on its local storage in a fast intermediate format”
↩︎ Key concept“This name change seeks to resolve confusion that it was part of the Delta Lake protocol.”
↩︎ Exam trap 1“You can write, modify, and delete table data with no need to explicitly invalidate cached data.”
↩︎ Exam trap 2“Use the disk cache instead of the Apache Spark cache for repeated reads of Parquet and Delta Lake data.”
↩︎ Exam trap 3“Databricks enables it automatically on worker instance types that support it.”
↩︎ Exam trap 4“Disk caching behavior is a proprietary Databricks feature. This name change seeks to resolve confusion that it was part of the Delta Lake protocol.”
↩︎ Checkpoint“Disabling the cache does not result in dropping the data that is already in the local storage.”
↩︎ Prediction - 2.https://docs.databricks.com/aws/en/lakehouse-architecture/performance-efficiency/best-practicesOfficial docs
“It can improve the performance for a wide range of queries but cannot be used to store the results of arbitrary subqueries.”
↩︎ How the disk cache turns remote reads into local reads“Caches can be prewarmed by running specific queries to initialize caches (for example, after a cluster restart).”
↩︎ Staying consistent after writes, and losing the cache“can store the result of any subquery data and data stored in formats other than Parquet (such as CSV, JSON, and ORC)”
↩︎ Disk cache versus Spark cache() and persist“However, using incorrect locations in a query can consume all available memory and significantly slow down queries.”
↩︎ Disk cache versus Spark cache() and persist - 3.
“Both caches are invalidated when the underlying tables are updated.”
↩︎ How the disk cache turns remote reads into local reads“The disk cache shares the same lifecycle characteristics as the local result cache.”
↩︎ Staying consistent after writes, and losing the cache - 4.
“If the stage reads the same data multiple times, use the disk cache.”
↩︎ Which compute has the disk cache, and how to configure it - 5.https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-syntax-aux-cache-cache-tableOfficial docs
“Databricks recommends against using CACHE TABLE as it is not compatible with Databricks serverless compute architecture.”
↩︎ Disk cache versus Spark cache() and persist“If storageLevel is not explicitly set using OPTIONS clause, the default storageLevel is set to MEMORY_AND_DISK.”
↩︎ Disk cache versus Spark cache() and persist