Skip to content

Lesson 3 ยท Getting Started

How DVC Works: Hashes, Cache and Links

Understand the DVC cache: content hashes, how files and directories are stored, why identical data is saved once, and how reflinks, hardlinks and copies differ.

Almost every DVC command makes more sense once you know how the cache works. This lesson opens the box: how content gets a name, where it is stored, and how it appears in your project folder.

Content-addressed storage

Most filing systems name things by location: data/train.csv. A content-addressed store names things by what is inside them. DVC computes a hash of the file contents (MD5) and uses that hash as the storage name. As of December 2026, the documentation says MD5 is the only type supported for the hash field in .dvc files. Some external locations use their own identifiers, such as an ETag.

In the DVC 3 layout, the first two characters of the hash form a folder and the rest form the file name:

TEXT
.dvc/cache/files/md5/
  ec/
    1d2935f811b77cc49b031b999cbf17    <- the file content

(The hash above is only an illustration.) Splitting by two characters keeps any single folder from holding too many files.

Two consequences follow:

  • Same content is stored once. Two files with identical bytes, even with different names, share one cache object.
  • A change creates a new object. The old object stays, so old versions remain available until you clean the cache.

MD5 is used here to identify content, not to protect secrets. Do not treat a hash as a security control.

Directories

When you track a folder, DVC stores each file inside it separately. It also stores a small .dir object: a JSON list that maps each file hash to its relative path. That list is enough to rebuild the folder.

JSON
[
  {"md5": "0cc175b9c0f1b6a831c399e269772661", "relpath": "cats/1.jpg"},
  {"md5": "92eb5ffee6ae2fec3ad71c777531578f", "relpath": "dogs/1.jpg"}
]

If you change one image in a folder of 10,000, only that image and the new .dir list are new objects. Everything else is reused. Note that DVC versions whole files: if you change one line in a huge CSV, the entire new file is stored. Splitting large data into several files (by date or by part) can save a lot of space.

Try the idea

This stand-in builds a tiny content-addressed store in memory. Real DVC writes to disk and handles many more details.

Python Stand-in: a mini content-addressed cache

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first version has three files but only two distinct contents, plus one listing. The second version adds two objects, even though the folder still has three files.

How files reach your workspace

The cache holds the content. Your project folder (the workspace) needs files with normal names. DVC links or copies them from the cache. The setting is cache.type.

Type How it works Edit in place?
reflink Copy-on-write clone on file systems that support it Safe
copy A full second copy Safe, but uses more disk
hardlink Two names for the same data Unsafe, so files are made read-only
symlink A pointer to the cache file Unsafe, so files are made read-only

The default is reflink,copy: DVC tries a reflink, and if the file system does not support it, it copies. Many common setups fall back to copying, which means large data takes disk space twice.

With hardlink or symlink, editing the workspace file in place could damage the cache. DVC protects you by making the files read-only. To change one, run dvc unprotect <file> first, or delete the file and write a new one.

Terminal
# Read-only: save disk space with links, then rebuild the workspace links
dvc config cache.type "reflink,hardlink,copy"
dvc checkout --relink

Where the cache lives

By default it is .dvc/cache. You can move it with dvc cache dir /path/to/cache, for example to a larger disk. A shared server may use one cache for several people (covered in Cleaning Storage and Best Practices). A separate folder called the site cache holds indexes and hash databases, which help DVC avoid hashing unchanged files again. Do not confuse it with the data cache.

Common mistake: treating the local cache as a backup. It usually lives on the same disk as your project. If the disk fails or you delete the folder, versions that you never pushed to a remote are gone.

Why hashes make reproducibility possible

A hash answers one question reliably: is this the same content as before? DVC uses that question everywhere. It knows whether your workspace differs from a recorded version, whether a pipeline stage needs to run again, and which objects the remote is missing. It does not tell you whether the data is correct. Quality checks are a separate job.

Estimate your storage

A little arithmetic helps you plan. Suppose a dataset folder holds 1,000 files of 2 MB each, so one version is about 2 GB. If a new version changes 50 files, the new objects add about 100 MB plus the small listing. If you had stored the same data as one 2 GB archive, every change would add roughly another full archive.

With the copy link type, the workspace also holds a second copy of the current version, so plan disk space for the cache history plus the checked-out files. Reflinks or hardlinks can reduce that second copy, with the editing rules shown above. Measure your real data before choosing, and prefer safe settings until disk space is truly a problem.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Two files with different names have identical contents. How many cache objects do they need?

    The cache is addressed by content, so identical bytes are stored once.
  2. 2. What does DVC store for a tracked directory?

    The listing maps hashes to relative paths so the folder can be rebuilt.
  3. 3. Why are hardlinked or symlinked workspace files read-only?

    The workspace file and the cache share data, so DVC protects it. Use dvc unprotect before editing.
  4. 4. You change one line in a large tracked CSV. What happens to storage?

    DVC versions whole files, not line-level differences.

Summary

  • The DVC cache names content by its MD5 hash.
  • Identical content is stored once; changed content becomes a new object.
  • A tracked folder gets a .dir listing plus one object per distinct file.
  • cache.type controls whether the workspace uses reflinks, copies, hardlinks or symlinks.
  • The local cache is not a backup.

Next: Track Data with dvc add

Your progress is saved in this browser. No account needed.