Skip to content

Commit

Permalink
1 min cache for 404 tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmatei committed Dec 4, 2024
1 parent 6b6e06d commit 2dede3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 0 additions & 2 deletions libs/common/src/providers/xexchange/xexchange.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ export class XExchangeService implements IProviderService {
});
}

this.logger.log(`Found ${pairs.length} pairs: ${pairs.map((p) => p.address).join(", ")}`);

return pairs;
}

Expand Down
17 changes: 11 additions & 6 deletions libs/common/src/services/multiversx.api/multiversx.api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from "@nestjs/common";
import { Token } from "./entities";
import { ApiService } from "@multiversx/sdk-nestjs-http";
import { ApiConfigService, CacheInfo } from "@mvx-monorepo/common";
import { OriginLogger } from "@multiversx/sdk-nestjs-common";
import { Constants, OriginLogger } from "@multiversx/sdk-nestjs-common";
import { CacheService } from "@multiversx/sdk-nestjs-cache";

@Injectable()
Expand All @@ -16,11 +16,16 @@ export class MultiversXApiService {
) { }

public async getToken(identifier: string): Promise<Token | null> {
return await this.cacheService.getOrSet(
CacheInfo.Token(identifier).key,
async () => await this.getTokenRaw(identifier),
CacheInfo.Token(identifier).ttl,
);
const cachedToken = await this.cacheService.get<Token>(CacheInfo.Token(identifier).key);
if (cachedToken) {
return cachedToken;
}

const tokenRaw = await this.getTokenRaw(identifier);

await this.cacheService.set(CacheInfo.Token(identifier).key, tokenRaw, tokenRaw ? CacheInfo.Token(identifier).ttl : Constants.oneMinute());

return tokenRaw;
}

public async getTokenRaw(identifier: string): Promise<Token | null> {
Expand Down

0 comments on commit 2dede3a

Please sign in to comment.