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

Clear InMemoryCache watches when cache.reset() called #8826

Merged
merged 3 commits into from
Sep 23, 2021

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Sep 22, 2021

This may help with memory management during SSR (provided cache.reset() is called), per my comment #7942 (comment).

Reusing the same cache between SSR requests is typically not what we recommend, since creating a new client/cache for each request is such an easy and effective way to prevent data from leaking between requests from different users/clients.

However, if you're careful to reset the cache each time, or you have non-SSR reasons for resetting the cache, it seems reasonable to expect the cache.watches to be emptied after the reset.

This should help with memory management during SSR, per my comment
#7942 (comment)
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

Awesome - thanks @benjamn!

@benjamn benjamn merged commit 372eb8f into main Sep 23, 2021
@benjamn benjamn deleted the clear-watches-when-cache.reset-called branch September 23, 2021 14:54
benjamn added a commit that referenced this pull request Sep 27, 2021
As reported in issue #8851, PR #8826 was a breaking change for code
expecting cache.watches to be restarted after cache.reset() is called.

This commit establishes a small but extensible Cache.ResetOptions API
for the cache.reset method, which allows the handling of watches to be
configured via options.discardWatches, which defaults to false, thus
restoring the behavior of cache.reset() from before #8826.

If you need the behavior introduced by #8826, you can now opt (back)
into that behavior by calling cache.reset({ discardWatches: true }).
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants