auths
objectreturn
or this.key = 'value'
, pass input data to your code viaparams
, and maintain state across executions with$checkpoint.async
(event, steps) => {
}
const axios = require("axios")
const cache = $checkpoint || {}
const now = +new Date()
// Replace with whatever variable references your primary key
const { key } = steps.trigger.event.body
if (key in cache) {
console.log(`Key ${key} is in cache`)
const { expiry, data } = cache[key]
if (expiry > now) {
return data
}
}
console.log(`Key ${key} is not in cache. Fetching data`)
// Since we don't have data cached for the key,
// or the data was expired, hit the API directly
const { data } = await axios({
method: "GET",
url: `https://swapi.dev/api/people/${key}`
})
$checkpoint = {
...cache,
[key]: {
data,
expiry: now + (1000 * 60 * 60 * 24) // expiry one day in the future
},
}
return data