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

Fix SWR Cache Quota #223

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Fix SWR Cache Quota #223

wants to merge 3 commits into from

Conversation

h0ngcha0
Copy link
Member

@h0ngcha0 h0ngcha0 commented Nov 2, 2024

SWR Cache uses the localStorage as backend, which has a 10MB limit. The one uses the most space is the infinite scroll cache for transactions (~75% for my wallet)

This PR:

  1. Cleanup the infinite scroll cache for accounts other than the selected one
  2. For useArrayStorage, only cache the selected results instead of all results

Copy link
Member

@Lbqds Lbqds left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@@ -129,3 +132,25 @@ function buildGetTransactionsFn(metadataTransactions: Transaction[]) {
)
}
}

export async function pruneTransactionsInfiniteScrollCache() {
Copy link
Member

Choose a reason for hiding this comment

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

Does this function try to clear the cache of unselected accounts?

Copy link
Member Author

@h0ngcha0 h0ngcha0 Nov 4, 2024

Choose a reason for hiding this comment

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

Yes, if we have a selected account (we normally have unless this is a new wallet), then it will clear the cache for infinite scroll transaction for all other unselected accounts.

Copy link
Member

Choose a reason for hiding this comment

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

If I switch accounts twice, does it mean all account cache for scrolling would be removed?

Copy link
Member Author

@h0ngcha0 h0ngcha0 Nov 4, 2024

Choose a reason for hiding this comment

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

If we switch account and close & open the extension wallet, it will clear all the account cache for transactions infinite scroll. Only switching account won't clear all scrolling cache.

The consequence of not having the infinite scroll cache is that if we click the activity tab to look at transaction history, it will try to fetch from the explorer backend immediately

Do you think this is too aggressive?

Copy link
Member

Choose a reason for hiding this comment

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

Does SWR support LRU cache with a limited capacity? LRU cache can handle clearing automatically.

Copy link
Member Author

@h0ngcha0 h0ngcha0 Nov 4, 2024

Choose a reason for hiding this comment

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

SWR doesn't seem to have built-in support for LRU cache with limited capacity. I can investigate if we can integrate with custom cache provider to achieve this.

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.

3 participants