@@ -221,6 +221,7 @@ private boolean getIsSdkEnabled() {
221221 // 2. If the value exists in device cache, return this value.
222222 // 3. Otherwise, return default value.
223223 SdkEnabled config = SdkEnabled .getInstance ();
224+ Optional <Boolean > deviceCacheValue = getDeviceCacheBoolean (config );
224225
225226 // 1. Reads value from Firebase Remote Config, saves this value in cache layer if fetch status
226227 // is not failure.
@@ -230,13 +231,17 @@ private boolean getIsSdkEnabled() {
230231 if (remoteConfigManager .isLastFetchFailed ()) {
231232 return false ;
232233 }
233- // b. Cache and return this value.
234- deviceCacheManager .setValue (config .getDeviceCacheFlag (), rcValue .get ());
235- return rcValue .get ();
234+
235+ Boolean newValue = rcValue .get ();
236+ // b. Only cache and return this value if it is different from the current value.
237+ if (!deviceCacheValue .isAvailable () || deviceCacheValue .get () != newValue ) {
238+ deviceCacheManager .setValue (config .getDeviceCacheFlag (), newValue );
239+ }
240+
241+ return newValue ;
236242 }
237243
238244 // 2. If the value exists in device cache, return this value.
239- Optional <Boolean > deviceCacheValue = getDeviceCacheBoolean (config );
240245 if (deviceCacheValue .isAvailable ()) {
241246 return deviceCacheValue .get ();
242247 }
@@ -257,17 +262,21 @@ private boolean getIsSdkVersionDisabled() {
257262 // 2. If the value exists in device cache, return this value.
258263 // 3. Otherwise, return default value.
259264 SdkDisabledVersions config = SdkDisabledVersions .getInstance ();
265+ Optional <String > deviceCacheValue = getDeviceCacheString (config );
260266
261267 // 1. Reads value from Firebase Remote Config, cache and return this value.
262268 Optional <String > rcValue = getRemoteConfigString (config );
263269 if (rcValue .isAvailable ()) {
264270 // Do not check FRC last fetch status because it is the most recent value device can get.
265- deviceCacheManager .setValue (config .getDeviceCacheFlag (), rcValue .get ());
266- return isFireperfSdkVersionInList (rcValue .get ());
271+ String newValue = rcValue .get ();
272+ // Only cache and return this value if it is different from the current value.
273+ if (!deviceCacheValue .isAvailable () || !deviceCacheValue .get ().equals (newValue )) {
274+ deviceCacheManager .setValue (config .getDeviceCacheFlag (), newValue );
275+ }
276+ return isFireperfSdkVersionInList (newValue );
267277 }
268278
269279 // 2. If the value exists in device cache, return this value.
270- Optional <String > deviceCacheValue = getDeviceCacheString (config );
271280 if (deviceCacheValue .isAvailable ()) {
272281 return isFireperfSdkVersionInList (deviceCacheValue .get ());
273282 }
0 commit comments