Skip to content

Commit

Permalink
improve(ApiClient): Randomize /limits cache TTL (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholaspai authored Mar 25, 2024
1 parent 80fe329 commit 286fefb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/clients/AcrossAPIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ export class AcrossApiClient {
}
if (redis) {
// Cache limit for 5 minutes.
await redis.set(this.getLimitsCacheKey(l1Token, destinationChainId), result.data.maxDeposit.toString(), 300);
const baseTtl = 300;
// Apply a random margin to spread expiry over a larger time window.
const ttl = baseTtl + Math.ceil(_.random(-0.5, 0.5, true) * baseTtl);
await redis.set(this.getLimitsCacheKey(l1Token, destinationChainId), result.data.maxDeposit.toString(), ttl);
}
return result.data;
} catch (err) {
Expand Down

0 comments on commit 286fefb

Please sign in to comment.