Basic

Application state and its owner

The app can hold anything. Holding something is a decision about who owns it, and the owner is the reason a reload does not lose it.

What you will see

One line. Losing the cache is fine, losing the config is not.

About 1 min of reading

Try It

Name the owner of each value

1

Write the values with owners

printf 'config app\ncache app\nsecret env\n' > /tmp/o.txt; grep env /tmp/o.txt

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

What it prints
secret env. The secret is owned outside the app, which is the rule.
2

Count the writers

printf 'config 0\ncache 2\n' > /tmp/w.txt; awk '{print $1, ($2==0 ? "read-only" : "guarded")}' /tmp/w.txt

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

What it prints
config read-only, cache guarded. The count decides the word.
3

Check a restart keeps it

printf 'restart keeps=config loses=cache\n' > /tmp/r.txt; cat /tmp/r.txt

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

What it prints
One line. Losing the cache is fine, losing the config is not.

Data Flow

A value to an owner
1 The value is declared on the app
↓
2 The owner is written with it
↓
3 The writers are counted
↓
4 A restart is checked against the owner
Why this works
Why the owner is written down

The owner is the reason a restart is safe. A restart that loses state is a restart whose owner was never named.

The one thing never to hold

Anything that changes with the request. Request scope is a parameter, and a parameter has an owner already.

Examples

Config is owned by the app

It is set at creation and read forever. Forever read means never written, which means no race.

A cache is not config

It is written during a run. Written during a run means the owner must say when it may be written.

Secrets are owned by nobody

They are read from outside and never stored on the object. Stored on the object means printed by a debug page.

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.

← Responses are built, not returned
Previous Lesson
Responses are built, not returned
Next Lesson
The debugger is a switch
The debugger is a switch →