Skip to content
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(rpc-provider): allow cacheCapacity option for WsProvider #5778

Merged
merged 2 commits into from
Jan 26, 2024

Conversation

TarikGul
Copy link
Member

Summary:

This PR aims to allow configuring the cacheCapacity for the LRUCache used in the WsProvider. It will still default to 128 if no option is passed in.

Concerns

This PR will be a breaking change for users that use the timeout option. I did think about creating an options object instead and including some of the args in there but I thought I would leave it up to discussion.

Feel free to close the PR if there is no intention to allow configuration of the capacity size of the LRU cache.

@@ -108,7 +108,7 @@ export class WsProvider implements ProviderInterface {
* @param {Record<string, string>} headers The headers provided to the underlying WebSocket
* @param {number} [timeout] Custom timeout value used per request . Defaults to `DEFAULT_TIMEOUT_MS`
*/
constructor (endpoint: string | string[] = defaults.WS_URL, autoConnectMs: number | false = RETRY_DELAY, headers: Record<string, string> = {}, timeout?: number) {
constructor (endpoint: string | string[] = defaults.WS_URL, autoConnectMs: number | false = RETRY_DELAY, headers: Record<string, string> = {}, cacheCapacity: number = DEFAULT_CAPACITY, timeout?: number) {
Copy link
Member

@jacogr jacogr Jan 12, 2024

Choose a reason for hiding this comment

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

Rather move this as the last parameter. (No breaking change - we really don't like breaking changes at all, unless very much required)

On use can do this.#callCache = new LRUCache(cacheCapacity || DEFAULT_CAPACITY); to apply defaults.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I just applied the change you recommended and I agree it makes more sense.

@TarikGul TarikGul requested a review from jacogr January 12, 2024 14:55
@TarikGul
Copy link
Member Author

@jacogr Apologies for pinging you, the PR is ready for another review whenever you have a chance. Thanks again for everything.

@jacogr jacogr merged commit c5371c1 into polkadot-js:master Jan 26, 2024
4 checks passed
@polkadot-js-bot
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jan 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants