@@ -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,19 @@ 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 == null
238+ || !deviceCacheValue .isAvailable ()
239+ || deviceCacheValue .get () != newValue ) {
240+ deviceCacheManager .setValue (config .getDeviceCacheFlag (), newValue );
241+ }
242+
243+ return newValue ;
236244 }
237245
238246 // 2. If the value exists in device cache, return this value.
239- Optional <Boolean > deviceCacheValue = getDeviceCacheBoolean (config );
240247 if (deviceCacheValue .isAvailable ()) {
241248 return deviceCacheValue .get ();
242249 }
@@ -257,17 +264,23 @@ private boolean getIsSdkVersionDisabled() {
257264 // 2. If the value exists in device cache, return this value.
258265 // 3. Otherwise, return default value.
259266 SdkDisabledVersions config = SdkDisabledVersions .getInstance ();
267+ Optional <String > deviceCacheValue = getDeviceCacheString (config );
260268
261269 // 1. Reads value from Firebase Remote Config, cache and return this value.
262270 Optional <String > rcValue = getRemoteConfigString (config );
263271 if (rcValue .isAvailable ()) {
264272 // 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 ());
273+ String newValue = rcValue .get ();
274+ // Only cache and return this value if it is different from the current value.
275+ if (deviceCacheValue == null
276+ || !deviceCacheValue .isAvailable ()
277+ || !deviceCacheValue .get ().equals (newValue )) {
278+ deviceCacheManager .setValue (config .getDeviceCacheFlag (), newValue );
279+ }
280+ return isFireperfSdkVersionInList (newValue );
267281 }
268282
269283 // 2. If the value exists in device cache, return this value.
270- Optional <String > deviceCacheValue = getDeviceCacheString (config );
271284 if (deviceCacheValue .isAvailable ()) {
272285 return isFireperfSdkVersionInList (deviceCacheValue .get ());
273286 }
0 commit comments