max / makenotwork
1 file changed,
+11 insertions,
-0 deletions
| @@ -1,4 +1,15 @@ | |||
| 1 | 1 | //! Idempotency key storage for safe POST retries. | |
| 2 | + | //! | |
| 3 | + | //! These functions are the storage layer for [`crate::metrics::idempotency_middleware`], | |
| 4 | + | //! the global POST/PUT replay guard mounted on the router: it reads | |
| 5 | + | //! [`get_cached_response`] before running a handler and writes [`store_response`] | |
| 6 | + | //! (fire-and-forget, via the background pool) on a successful 2xx/3xx response, | |
| 7 | + | //! scoped to `(key, user_id, method, path)`. The scheduler calls | |
| 8 | + | //! [`cleanup_expired`] on its daily tick. This is distinct from — and additive | |
| 9 | + | //! to — the structural checkout dedup (the `(buyer_id, item_id) WHERE | |
| 10 | + | //! status='pending'` partial unique index): the index makes a double checkout | |
| 11 | + | //! unrepresentable; this cache replays the *response* of any retried POST/PUT. | |
| 12 | + | //! Exercised end-to-end by `tests/workflows/idempotency.rs`. | |
| 2 | 13 | ||
| 3 | 14 | use sqlx::PgPool; | |
| 4 | 15 | use crate::db::UserId; |