Firebase remote config always hit server
Asked Answered
E

1

6

I started to have a look on firebase remote config, I read the documentation and created a simple test application to understand how the cache works, but the behaviour is not clear to me.

In the code below everytime I change the welcome_message property and click the fab button the new value of the property is fetched, I was expecting to get the new value only after the cache expires.

public class MainActivity extends AppCompatActivity {

    private FirebaseRemoteConfig remoteConfig;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = findViewById(R.id.fab);
        fab.setOnClickListener(this::fabClickListener);
        remoteConfig = FirebaseRemoteConfig.getInstance();

        FirebaseRemoteConfigSettings configSettings = new FirebaseRemoteConfigSettings.Builder()
                .setDeveloperModeEnabled(false)
//                .setDeveloperModeEnabled(BuildConfig.DEBUG)
                .build();
        remoteConfig.setConfigSettings(configSettings);
        remoteConfig.setDefaults(R.xml.firebase_remote_properties);
    }

    private void fabClickListener(View view) {
        String welcomeMessage = remoteConfig.getString("welcome_message");
        Snackbar.make(view, welcomeMessage, Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();

        remoteConfig.fetch(60_000)
                .addOnFailureListener(exception -> Toast.makeText(this, "Fetch Failed", Toast.LENGTH_SHORT).show())
                .addOnSuccessListener(result -> {
                    Toast.makeText(this, "Fetch Succeeded", Toast.LENGTH_SHORT).show();
                    remoteConfig.activateFetched();
                })
                .addOnCanceledListener(() -> Toast.makeText(this, "Fetch Canceled", Toast.LENGTH_SHORT).show());
    }

    ...
}

Checking fetch documentation I see

To identify the current app instance, the fetch request creates a Firebase Instance ID token, which periodically sends data to the Firebase backend

On every new fetch call a new ID is created? Also how the periodical requests works? I was expecting to call fetch only once and for a request to be sent automatically when a stale property value is requested or something similar

Esau answered 4/3, 2019 at 14:23 Comment(2)
I don't fully understand the question. Are you saying that every time you call fabClickListener, the Toast.makeText(this, "Fetch Succeeded" is shown?Loincloth
Hello @FrankvanPuffelen the toast is actually displayed everytime, but that is not the issue here, I expected the success listener to be called even if the value were fetched from cache. The issue I'm experiencing is the new property is always fetched, therefore I see the Toast messsage with the welcome_message new value (in the next click after the fetch) even though the cache should still be validEsau
H
2

Firebaser here!

This is a known issue which affects Remote Config SDK 16.3.0. We are actively working on a fix for the next release.

Hirz answered 8/3, 2019 at 22:45 Comment(1)
Thank you for your comment, but it doesn't really answer the question. Can you give more details on the bug and what is the expected behaviour?Esau

© 2022 - 2024 — McMap. All rights reserved.