A dispatch console caches incident summaries, expires temporary states, recycles incident slots, and schedules work by priority. These are four separate lifecycles. Implement a plain reference alongside each index: scan resident cache entries for minimum frequency and oldest tie, scan live expiration records at an explicit clock value, keep every issued handle with its expected live or stale status, and sort queued tasks by priority followed by insertion order. Compare the result after every operation. A cached value may still exist while its TTL entry has expired; a freed slot may be reused while its previous handle remains invalid. Treat these differences as contracts, not as implementation details to smooth over.
Project: audit incident retention and dispatch
Acceptance trace
Cache pump-47 and valve-19 at capacity two, read pump-47, then add sensor-61: valve-19 leaves. Write pump-47 at time 23 for 19 units and replace it at time 29 for 38 units: the replacement survives the old deadline 42 and expires at 67. Remove the first handle for pump-47, then insert valve-19 into its slot: the first handle must fail and the new one must resolve. For four-way dispatch, insert priorities 47, 19, 19, and 61 in that order; the two priority-19 incidents leave in their arrival order.
Expected output
evicted=valve-19 at-42=rechecked at-67=none
old-handle=stale dispatch=[valve, sensor, pump, grid]Boundary and cost review
Try zero cache capacity, a frequency tie, an overwritten key with several old expiry records, zero lifetime, backward time, a foreign-store handle, repeated removal, an empty dispatch heap, and equal priorities with non-comparable task objects. State the memory bound for each component. Lazy expiry records can outnumber live keys; the slot store retains its highest allocated size even after deletion; and the heap keeps only pending tasks. The examples model single-process state. Durable scheduling, synchronization, generation overflow in fixed-width languages, and cache frequency aging require separate designs.
Common Mistakes
- Do not break LFU ties with newest-first eviction.
- Do not let an old expiry record remove a replacement.
- Do not resolve a handle solely by its slot number.
- Do not compare task objects on equal priority.
