Skip to content

Commit

Permalink
Merge pull request #17 from RootstockCollective/feat/cache
Browse files Browse the repository at this point in the history
feat: cache for events
  • Loading branch information
Freshenext authored Oct 28, 2024
2 parents ca6d8dd + 0f19ebd commit baa0980
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/blockscoutApi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,13 @@ export class BlockscoutAPI extends DataSource {
address,
sort: 'asc'
}
const response = await this.axios?.get<ServerResponse<BlockscoutTransactionResponseTxResult>>(
this.url, { params }
const response = await this.axiosCache.get<ServerResponse<BlockscoutTransactionResponseTxResult>>(
this.url, {
params,
cache: {
ttl: 1000 * 60 * 15
}
}
)

if (!response?.data) {
Expand Down Expand Up @@ -177,7 +182,7 @@ export class BlockscoutAPI extends DataSource {
fromBlock: fromBlockToUse,
topic0
}
return this.axios?.get<ServerResponse<TokenTransferApi>>(`${this.url}`, { params })
return this.axiosCache.get<ServerResponse<TokenTransferApi>>(`${this.url}`, { params })
.then(({ data }) => data.result)
.catch(() => [])
}
Expand Down Expand Up @@ -208,7 +213,7 @@ export class BlockscoutAPI extends DataSource {
async getNftInstancesByAddress ({ address, nextPageParams }: GetNftHoldersData) {
const url = `${this.url}/v2/tokens/${address.toLowerCase()}/instances`
try {
const response = await this.axios?.get<ServerResponseV2<NftTokenHoldersResponse>>(url, {
const response = await this.axiosCache.get<ServerResponseV2<NftTokenHoldersResponse>>(url, {
params: nextPageParams,
validateStatus: (status) => status <= 500
})
Expand Down

0 comments on commit baa0980

Please sign in to comment.