Advanced

Caching by content, not by time

A cache that asks when is a cache that lies. The content hash is the identity, and the identity is why a rebuild is skipped honestly.

What you will see

key complete. A template change must not skip.

About 1 min of reading

Try It

Prove a skip

1

Hash the same content twice

printf 'body\n' | sha256sum; printf 'body\n' | sha256sum

Before you run it, say out loud what it will print. Then open the answer.

What it prints
The same hash twice. Same content is the same identity.
2

Count a skip

printf 'skipped 9 written 3\n' | awk '{print $2+$4}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
12. Skipped plus written is the total, which is the claim.
3

Put the template in the key

printf 'page-hash template-hash\n' | awk '{print ($2=="") ? "key incomplete" : "key complete"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
key complete. A template change must not skip.

Data Flow

Content to a skip or a write
1 The content and the template are hashed together
↓
2 The hash is looked up
↓
3 A hit skips and counts
↓
4 A miss writes and records the hash
Why this works
Why time is never the key

A time changes without the content changing. A changed time and the same content is a rebuild that lies.

The one file that must be in the key

The template. A template change with the same content is a page that must be written again.

Examples

The key is the hash

The hash of the content. Same content is the same hash, and the same hash is the skip.

The name carries the hash

The version in the name is the hash. One identity is what makes the cache and the name agree.

A skip is reported

Skipped is a number in the report. A number is what makes a fast build a claim.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Assets with a version in the name
Previous Lesson
Assets with a version in the name
Next Lesson
Drafts as a written switch
Drafts as a written switch →