Skip to content

Commit

Permalink
fix: update doh to new iso-kv ttl in seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Feb 5, 2024
1 parent 6452696 commit 6023226
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions packages/iso-web/src/doh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,23 +195,23 @@ export async function resolve(query, type, options = {}) {
const out = {
error: new DohError(error, { data: result }),
}
await cache.set([url], out, 3600) // caches errors for 1 hour
await cache.set([url], out, { ttl: 3600 }) // caches errors for 1 hour
return out
}

if (result.Answer) {
const data = result.Answer.map((a) => a.data.replaceAll(/["']+/g, ''))
const ttl = Math.min(...result.Answer.map((a) => a.TTL))
const out = { result: data }
await cache.set([url], out, ttl)
await cache.set([url], out, { ttl })
return out
}

if (result.Authority) {
const data = result.Authority.map((a) => a.data)
const ttl = Math.min(...result.Authority.map((a) => a.TTL))
const out = { result: data }
await cache.set([url], out, ttl)
await cache.set([url], out, { ttl })
return out
}

Expand Down
2 changes: 1 addition & 1 deletion packages/iso-web/test/doh.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ test('should resolve from cache', async () => {
}

// second from cache
await cache.set([url], { result: [1] }, 1)
await cache.set([url], { result: [1] }, { ttl: 1 })

const out1 = await resolve('google.com', 'A', {
cache,
Expand Down

0 comments on commit 6023226

Please sign in to comment.