Something like this ```typescript const defaultPayload = { hits: 1, expiration: new Date(new Dat

Something like this
const defaultPayload = {
  hits: 1,
  expiration: new Date(new Date().getTime() + 60_000),
}

const record = await env.NAMESPACE.get('key', { type: 'json' })

const payload = {
  ...defaultPayload,
  ...(record ?? {}), // if record is nullish, spread an empty object in its place
}

await env.NAMESPACE.put('key', payload, { expiration: payload.expiration })
Was this page helpful?