Files
Qris-Soundbox/dist/shared/idempotency/idempotencyStore.js
2026-05-25 08:22:12 +07:00

27 lines
704 B
JavaScript

const store = new Map();
export function makeIdempotencyKey(scope, key) {
return `${scope}:${key}`;
}
export function readIdempotency(scope, key) {
const entry = store.get(makeIdempotencyKey(scope, key));
if (!entry) {
return null;
}
if (entry.expiresAt < Date.now()) {
store.delete(makeIdempotencyKey(scope, key));
return null;
}
return entry.value;
}
export function writeIdempotency(scope, key, value, ttlMs) {
store.set(makeIdempotencyKey(scope, key), {
key,
scope,
value,
expiresAt: Date.now() + ttlMs
});
}
export function clearIdempotency(scope, key) {
store.delete(makeIdempotencyKey(scope, key));
}