Skip to content

fix: overriding cache persists cached data in subsequent calls - #46

Merged
NielsJPeschel merged 6 commits into
mainfrom
override-cache-persisting-data
Aug 28, 2026
Merged

fix: overriding cache persists cached data in subsequent calls#46
NielsJPeschel merged 6 commits into
mainfrom
override-cache-persisting-data

Conversation

@NielsJPeschel

@NielsJPeschel NielsJPeschel commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

The behavior of overrideCache should be such that when provided, any subsequent calls should reuse the same promise and or response that follow the new promise that gets created.

However, since we currently do not actually flush the cash, when attempting to override the cache, we have the following behavior:

const res1 = await lazyFetchData()

// some time later

const res2 = lazyFetchData(true);
const res3 = lazyFetchData();
const res4 = lazyFetchData();

res3 and 4 will actually return res1, as res2 has not yet resolved (thereby it has not yet updated useLazyLoadData's internal cache to reflect the new result)

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@NielsJPeschel
NielsJPeschel requested a review from nthurow August 28, 2026 19:54
Comment on lines +225 to +226
expect(r3).toBe('2');
expect(r4).toBe('2');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So without your changes, r3 and r4 would have both resolved to '1'?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Exactly!

@NielsJPeschel
NielsJPeschel merged commit 9db5982 into main Aug 28, 2026
5 checks passed
@NielsJPeschel
NielsJPeschel deleted the override-cache-persisting-data branch August 28, 2026 20:29
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.

2 participants