shouldCacheResponse decides whether finalize should Complete (cache the response) or Release the claim. Pulled out as a pure function so the policy can be unit-tested without standing up the full HTTP + DB stack. Rule: cache on 2xx/3xx always; cache on 4xx/5xx ONLY if the handler signalled that an
(statusCode int, sideEffectCommitted bool)
| 129 | // upstream send accepted, or the loopback DB rows landed). Otherwise |
| 130 | // Release so the caller can retry with the same key. |
| 131 | func shouldCacheResponse(statusCode int, sideEffectCommitted bool) bool { |
| 132 | if statusCode < 400 { |
| 133 | return true |
| 134 | } |
| 135 | return sideEffectCommitted |
| 136 | } |
| 137 | |
| 138 | // markSideEffectCommitted is called by handlers immediately after an |
| 139 | // irreversible action succeeds (an upstream SMTP/SES accept, a |
no outgoing calls