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 fetch from api after loading stale cache when skip api set #253

Merged
merged 4 commits into from
Sep 24, 2024

Conversation

blackjid
Copy link
Contributor

@blackjid blackjid commented Sep 17, 2024

I think I missed this in the #251 PR.

In this PR I added tests and code to maintain the behaviour of getting from the api when the cache expired and after loading the stale cache.

There is bad case where you might end up with a forever stale cache by using the loadStale: true, when you expected that it always fetch when the cache has expired..

cc: @kyle-ssg

@blackjid blackjid force-pushed the fix_load_stale_cache_skip_api branch from ef9c2ad to cba3282 Compare September 17, 2024 19:04
@kyle-ssg kyle-ssg self-requested a review September 18, 2024 10:37
const shouldFetchFlags = !preventFetch && (
!this.cacheOptions.skipAPI ||
!cachePopulated ||
(cachePopulated && staleCachePopulated)
Copy link
Member

@kyle-ssg kyle-ssg Sep 18, 2024

Choose a reason for hiding this comment

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

Hmm I think this can be tidied up, this is within an if(cachePopulated), so some of these are redundant ?

If I'm not mistaken should this be more like

  // fetch the flags if the cache is stale, or if we're not skipping api on cache hits
  const shouldFetchFlags = !preventFetch && (!this.cacheOptions.skipAPI || staleCachePopulated)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right... :) much cleaner

@kyle-ssg kyle-ssg self-requested a review September 18, 2024 10:39
@blackjid blackjid force-pushed the fix_load_stale_cache_skip_api branch from c0ac849 to ef4f22b Compare September 18, 2024 15:28
@kyle-ssg kyle-ssg merged commit 8d91a1c into Flagsmith:main Sep 24, 2024
1 check passed
@blackjid blackjid deleted the fix_load_stale_cache_skip_api branch September 24, 2024 09:43
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