-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: price in memory caching #31
Conversation
ZKS-120 Prices cache
Create an in-memory cache for token prices with 60s TTL. AC:
Optional: use |
libs/pricing/src/pricing.module.ts
Outdated
HttpModule, | ||
CacheModule.register({ | ||
store: "memory", | ||
ttl: 60, // seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't like this value hardcoded here, is there any better solution for this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we go with constants file ser 🫡
747ee85
to
8e0015d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to address the comment, but it's good to go as it is, very elegant cache handling. 💎
}, | ||
{ | ||
provide: WINSTON_MODULE_PROVIDER, | ||
useValue: mockLogger, | ||
}, | ||
{ | ||
provide: CACHE_MANAGER, | ||
useValue: createMock<Cache>({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty neat solution the createMock
utility function, didn't know it existed, nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its from some guys that made utilities and helpers for NestJs actually jajaja
LoggerModule, | ||
CacheModule.register({ | ||
store: "memory", | ||
ttl: TOKEN_CACHE_TTL_IN_SEC, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sweet
@@ -67,14 +80,15 @@ describe("CoingeckoService", () => { | |||
}); | |||
|
|||
describe("getTokenPrices", () => { | |||
it("return token prices", async () => { | |||
it("all token prices are fetched from Coingecko", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what ? 🤣
{} as Record<string, number>, | ||
); | ||
|
||
const missingTokenIds = tokenIds.filter((_, index) => !cachedTokenPrices[index]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this filter could be done inside the reduce i think
@@ -50,6 +52,62 @@ export class CoingeckoService implements IPricingService { | |||
): Promise<Record<string, number>> { | |||
const { currency } = config; | |||
|
|||
const cacheKeys = tokenIds.map((tokenId) => this.formatTokenCacheKey(tokenId, currency)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it posible to have sth like this on the Cache ?
{ < currency > : { < tokenId > : < amount > } }
iam not a huge fan of formatting keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@0xyaco would love to hear your opinion here ser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storing an object/map as value?
the thing is that we use only tokenId as key we will get a hit but we will have to analyze the response map for the currency
a simpler solution is an only USD service
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, i think we are not gona be using other currency as baseCurrency , lets keep it like it is for now
Co-authored-by: 0xyaco <[email protected]>
i think we need to fix the pr title. try with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
🤖 Linear
Closes ZKS-120
Description
Add an InMemory caching layer for token prices: