fastify · Hard · cache lifecycle
A production API needs a reference-counted service cache repair at its service boundary. Several panels subscribe to the same query. The current cache aborts the shared request when any panel unmounts and commits a late response after the final subscriber has gone.
Task
Implement the reference-counted service cache contract used by the supplied HTTP adapter. Reduce subscribe, unsubscribe, resolve and reject events into cache state with reference-counted ownership.
Contract
Input is {events}. subscribe/unsubscribe carry key and subscriber; resolve/reject carry key and requestId. Return entries keyed by query with subscribers, status, value, error and aborted request IDs.
Acceptance criteria
- One pending request is shared per key.
- Unsubscribing one consumer keeps work alive for remaining consumers.
- The last unsubscribe aborts and invalidates the request.
- Late settlements from invalidated requests are ignored.
- Return a deterministic JSON-serializable result for the HTTP adapter.
Constraints
- Do not mutate caller-owned input.
- Keep the supplied framework adapter and public contract unchanged.
- Add candidate tests for at least one boundary not covered by the public cases.
Editable files
src/repair.js— Task-specific state or service boundarytests/candidate.test.js— Candidate-authored regression