The cache that forgets
A cached result gets computed again. Only some values trigger it.
What’s going wrong
A lookup service should evaluate each unique key once per batch. A repeated key sometimes runs the lookup again, making the call counter too high.
Input is a JSON array of records with `key` (string) and `value` (any JSON value). The first record for a key supplies its value. Later records with that key must reuse the first result, even if they supply a different value. Print compact JSON with `values` in input order and `calls`, the number of actual lookups. An empty batch performs zero lookups.
Reproduce the repeated-null case, then fix `resolve` without changing the input/output contract.
Expected behavior
Every unique key is evaluated once. Every JSON value, including null, false, zero, and empty strings, is a valid cached result.
Reproduction
[{"key":"a","value":null},{"key":"a","value":null}]{"values":[null,null],"calls":1}[{"key":"x","value":7},{"key":"x","value":9}]{"values":[7,7],"calls":1}Before you begin
- Functions
- Dictionaries
- JSON values
Need a nudge?
Reveal one investigation hint at a time. Try each clue before opening the next.
Read the report, then sign in to start your investigation.