Skip to content

Commit

Permalink
fix(rpc): only cache lookups when finalized
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Oct 24, 2024
1 parent 687eba6 commit 73051aa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/iso-filecoin/src/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class Address {
}

const cached = await /** @type {typeof cache.get<string>}*/ (cache.get)(key)
if (cached) {
if (cached && options.safety === 'finalized') {
return AddressId.fromString(cached)
}

Expand All @@ -371,7 +371,9 @@ class Address {
)
}

await cache.set(key, idAddress.toString())
if (options.safety === 'finalized') {
await cache.set(key, idAddress.toString())
}
return idAddress
}

Expand All @@ -392,7 +394,7 @@ class Address {
const cache = getCache(options.cache)
const key = ['0x', this.toString()]
const cached = await /** @type {typeof cache.get<string>}*/ (cache.get)(key)
if (cached) {
if (cached && options.safety === 'finalized') {
return cached
}

Expand All @@ -410,7 +412,9 @@ class Address {
throw new Error(`Invalid ID masked 0x address: ${r.result}`)
}

await cache.set(key, r.result)
if (options.safety === 'finalized') {
await cache.set(key, r.result)
}
return r.result
}
}
Expand Down

0 comments on commit 73051aa

Please sign in to comment.