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 Android 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 OkHttp cache at context.cacheDir keys entries 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 cached responses. Unlike iOS there is no shared singleton, but the on disk cache is not environment namespaced.
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 (separate cache dir or environment scoped cache 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 Android 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 OkHttp cache at context.cacheDir keys entries 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 cached responses. Unlike iOS there is no shared singleton, but the on disk cache is not environment namespaced.
Steps to reproduce:
Proposed direction: namespace the cache per environment key (separate cache dir or environment scoped cache key) so instances don't collide