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

Caching with multiple instance doesn't work #201

Closed
ldemesla opened this issue Nov 21, 2023 · 10 comments · Fixed by #246
Closed

Caching with multiple instance doesn't work #201

ldemesla opened this issue Nov 21, 2023 · 10 comments · Fixed by #246
Assignees
Labels
bug Something isn't working

Comments

@ldemesla
Copy link

Hey,

I'm using Flagsmith with two instances, created using the createFlagsmithContext. I have noticed that caching is not working properly when you are running two instances. Indeed, if you look at the local storage you will see that the values from both instance are cached against the same key and are overriding each other.

Reproduction case:

communitiesFlag.init({
  environmentID: 'env-1',
  api: FLAGSMITH_API,
  cacheFlags: true,
  cacheOptions: {
    skipAPI: true,
    ttl: 1000 * 60 * 5,
  },
});

usersFlags.init({
  environmentID: 'env-2',
  api: FLAGSMITH_API,
  cacheFlags: true,
  cacheOptions: {
    skipAPI: true,
    ttl: 1000 * 60 * 5,
  },
});

usersFlags.identify('1')
communitiesFlag.identify('2')

Check in the local storage of your browser and you will see that only one of the identity has been cached

@matthewelwell
Copy link
Contributor

Thanks for this @ldemesla, we will look into it and get back to you as soon as possible.

@matthewelwell matthewelwell added the bug Something isn't working label Nov 21, 2023
@novakzaballa
Copy link
Contributor

Thank you @ldemesla! we will soon start working on this issue, and keep you posted about the progress.

@matthewelwell
Copy link
Contributor

@kyle-ssg @novakzaballa what's the status here?

@novakzaballa
Copy link
Contributor

Hi @ldemesla, just to leave an update and let you know that we are considering if this use case would be solved by the implementation of contexts which is planned to be delivered by the second semester of this year.

@novakzaballa
Copy link
Contributor

Hi @ldemesla we will start working on the contexts next week, could you please explain the use case for this request? so we can know this is a good candidate for solving this with the implementation of the contexts

@novakzaballa
Copy link
Contributor

Also, we don't provide the function createFlagsmithContext, in the javascript client, Could you please share where you found the code for using createFlagsmithContext?

@oluizcarvalho
Copy link
Contributor

@novakzaballa I am interested in solving the problem, my use case is the use of cacheFlags in a microfrontend architecture where each project can have its own instance of flagsmith but they all share the same localStorage

@matthewelwell
Copy link
Contributor

Hi @oluizcarvalho, that makes total sense to me. If you'd like to submit a PR for this, then we'd love to receive it!

@oluizcarvalho
Copy link
Contributor

@matthewelwell PR open! 🚀 #246

oluizcarvalho added a commit to oluizcarvalho/flagsmith-js-client that referenced this issue Sep 9, 2024
oluizcarvalho added a commit to oluizcarvalho/flagsmith-js-client that referenced this issue Sep 10, 2024
oluizcarvalho added a commit to oluizcarvalho/flagsmith-js-client that referenced this issue Sep 12, 2024
oluizcarvalho added a commit to oluizcarvalho/flagsmith-js-client that referenced this issue Sep 12, 2024
kyle-ssg added a commit that referenced this issue Sep 17, 2024
#201 (feat): added envId to the storage key and added property to cacheOptions to customize the key
@kyle-ssg kyle-ssg closed this as completed Oct 9, 2024
@kyle-ssg
Copy link
Member

kyle-ssg commented Oct 9, 2024

This has been resolved in version 6.0.0, thanks so much @oluizcarvalho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
5 participants