When two Flagsmith client instances run in the same app on different environment keys with caching enabled, they can serve or overwrite each other's cached flags.
Use case: a host app uses the Flagsmith iOS SDK, and a third-party SDK embedded in the same app also uses the Flagsmith SDK, each configured with its own environment key against the same base URL.
Observed behaviour: with caching on, flags from one environment can be returned for the other, or the two instances overwrite each other's cached values.
Likely cause (to validate): the cache appears keyed on request URL only. The environment is sent as the X-Environment-Key header and the flags path is fixed, so two instances on the same base URL share a cache entry. On iOS this is compounded by Flagsmith.shared being a singleton.
Steps to reproduce:
- Create two Flagsmith clients in one app, each with a different environment key, same API base URL, caching enabled.
- Fetch flags on client A, then client B.
- Observe client B serving client A's cached flags, or the two overwriting each other.
Proposed direction: namespace the cache per environment key so instances don't collide
When two Flagsmith client instances run in the same app on different environment keys with caching enabled, they can serve or overwrite each other's cached flags.
Use case: a host app uses the Flagsmith iOS SDK, and a third-party SDK embedded in the same app also uses the Flagsmith SDK, each configured with its own environment key against the same base URL.
Observed behaviour: with caching on, flags from one environment can be returned for the other, or the two instances overwrite each other's cached values.
Likely cause (to validate): the cache appears keyed on request URL only. The environment is sent as the X-Environment-Key header and the flags path is fixed, so two instances on the same base URL share a cache entry. On iOS this is compounded by Flagsmith.shared being a singleton.
Steps to reproduce:
Proposed direction: namespace the cache per environment key so instances don't collide