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

Add cache key elimination example #127

Closed
wants to merge 1 commit into from
Closed

Conversation

huozhi
Copy link
Member

@huozhi huozhi commented Jul 22, 2021

Related to #94

Tested with codesandbox demo

@vercel
Copy link

vercel bot commented Jul 22, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/vercel/swr-site/5Snkj9LqY1u16AwEnYHfSVXVAkxr
✅ Preview: https://swr-site-git-clear-cache-example.vercel.sh

@vercel-team
Copy link

Copy link
Member

@shuding shuding left a comment

Choose a reason for hiding this comment

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

Maybe we should link the Least Recently Used Map text to https://github.com/rsms/js-lru?

Q1: To make it simpler, can we just createCache(new LRUMap(8))?
Q2: This is more like a concern, it's possible to have an active key removed (so it might be possible to cause some internal logic incorrectness?). A safe impl might be using ref counting like vercel/swr#92. Maybe let's hide this example away for now, and provide an example for clearing the cache during testing (with Jest). WDYT?

@huozhi
Copy link
Member Author

huozhi commented Jul 22, 2021

@shuding sounds good to me, real-world inactive key detection would be much more complicated and not easy to demo in few lines.

@shuding
Copy link
Member

shuding commented Jul 22, 2021

Yeah, I think the more common cases are:

  • clear cache after each test case/suit
  • clear cache after logging out

Both cases are clearing the cache entirely. I don't see much value of selectively deleting cache values for saving memory for some JSON data.

After almost 3 years since open sourcing this lib we see no report on OOM caused by SWR, so I'm pretty sure this (automatic GC) is just the red herring and not a real demand (of course people can still do it if they want).

@huozhi
Copy link
Member Author

huozhi commented Jul 22, 2021

Close this one as it's not sth we'd like user to focus on. Provide

@huozhi huozhi closed this Jul 22, 2021
@huozhi huozhi deleted the clear-cache-example branch July 22, 2021 18:45
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