Skip to content

Conversation

@AngelCastilloB
Copy link
Member

Context

We want to reduce the amount of request we make to blockfrost. Now ChainHistoryProvider and UtxoProvider use a local volatile cache to reuse when requesting the same data several times.

const compareTx = (a: BlockfrostTx, b: BlockfrostTx) => a.block_height - b.block_height || a.tx_index - b.tx_index;

export class BlockfrostChainHistoryProvider extends BlockfrostProvider implements ChainHistoryProvider {
private readonly cache: Map<string, Cardano.HydratedTx> = new Map();
Copy link
Member

@mkazlauskas mkazlauskas Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if cache objects were injected (e.g. type Cache<K, V> = { get: (key: K) => Promise<T>, set: (key: K, value: V) => Promise<void> }), then it would be easier to update/swap it with a more sophisticated cache (lru, persistent etc.) and control it with FFs. Anyway happy to merge as-is to mitigate the current issue quickly.

@AngelCastilloB AngelCastilloB force-pushed the feat/cache-data-from-blockfrost-locally branch from 4dce93b to 8cb0dac Compare January 27, 2025 10:29
@rhyslbw rhyslbw removed the request for review from ginnun January 27, 2025 11:02
@AngelCastilloB AngelCastilloB merged commit fbc7429 into master Jan 27, 2025
5 of 6 checks passed
@AngelCastilloB AngelCastilloB deleted the feat/cache-data-from-blockfrost-locally branch January 27, 2025 11:12
@rhyslbw rhyslbw changed the title Feat/cache data from blockfrost locally LW-12164 Feat/cache data from blockfrost locally Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants