Skip to content

Commit

Permalink
Reset configs cache on locale change
Browse files Browse the repository at this point in the history
Signed-off-by: Elly Kitoto <[email protected]>
  • Loading branch information
ellykits committed Oct 23, 2023
1 parent 1c4af9a commit 2ce8123
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ constructor(
): T {
require(!configType.parseAsResource) { "Configuration MUST be a template" }
val configKey = if (configType.multiConfig && configId != null) configId else configType.name
// Temporarily Disable Caching for MLS demo Hotfix
if (configCacheMap.contains(configKey) && paramsMap?.isEmpty() == true && false) {
if (configCacheMap.contains(configKey) && paramsMap?.isEmpty() == true) {
return configCacheMap[configKey] as T
}
val decodedConfig =
Expand Down Expand Up @@ -599,6 +598,8 @@ constructor(
}
}

fun clearConfigsCache() = configCacheMap.clear()

companion object {
const val BASE_CONFIG_PATH = "configs/%s"
const val COMPOSITION_CONFIG_PATH = "configs/%s/composition_config.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ constructor(
is UserSettingsEvent.SwitchLanguage -> {
sharedPreferencesHelper.write(SharedPreferenceKey.LANG.name, event.language.tag)
event.context.run {
configurationRegistry.clearConfigsCache()
setAppLocale(event.language.tag)
getActivity()?.refresh()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ class UserSettingViewModelTest : RobolectricTest() {
Shadows.shadowOf(Looper.getMainLooper()).idle()

verify { sharedPreferencesHelper.write(SharedPreferenceKey.LANG.name, "es") }

Assert.assertTrue(configurationRegistry.configCacheMap.isEmpty())
}

@Test
Expand Down

0 comments on commit 2ce8123

Please sign in to comment.