Close the four earlier lessons and work from this brief. The workspace has
an executable case table but an unfinished run function. Complete the rule
before looking at the solution. Twenty-four minutes is a suggested first pass;
split the work across sessions if you need more time.
The brief
Return bypass for private data or an unauthorized caller. Otherwise return hit only before expiresAt, miss at or after expiry. A cache result must never grant access by itself.
Keep the function deterministic and leave its inputs unchanged. Explain how this rule connects to a Next.js page, action or route handler; the table is a contract harness, not a substitute for testing that transport.
Acceptance cases
- Input
{"isPrivate": true, "authorized": true, "now": 1, "expiresAt": 10}→"bypass". - Input
{"isPrivate": false, "authorized": false, "now": 1, "expiresAt": 10}→"bypass". - Input
{"isPrivate": false, "authorized": true, "now": 10, "expiresAt": 10}→"miss".
Add one case of your own to examples: the least convenient input you can
think of, such as an empty list, a missing field or a repeated value. Work out
its expected result before you run it. The table's Input kept column must
say yes on every row: the rule may not change what it was given.
npm install and npm run dev. Hint 1: the idea
Separate validation, calculation and output shaping. Decide the failure precedence before writing the happy path.
Hint 2: a first step
This is a policy model. Production cache behaviour must be verified against a real Next.js build with two distinct callers.
Show one solution
npm install and npm run dev. A matching output alone is not the whole check: the Input kept column must say yes too. Then explain the rule to yourself without reading the implementation.
Before the next day
- Which layer owns this decision, and which layer translates it for the reader?
- What happens on the least convenient input, not only the happy path?
- What would you test in a real browser or server that this pure function cannot establish?
Completion is saved in this browser only. It does not measure mastery.