Firebase cache expiration always as in debug mode
Asked Answered
P

1

6

I'm trying to implement Firebase Remote Config in my iOS app. Everything works fine, but there is a problem - a remote config always fetches data from firebase server, not from cache. I have tried a lot of variants without any success. This is my code:

+ (instancetype)sharedInstance
{
static ConfigManager *_sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    _sharedInstance = [[self alloc] init];

});
return _sharedInstance;
}

-(instancetype)init
{
self = [super init];
if (self) {
    self.remoteConfig = [FIRRemoteConfig remoteConfig];
    [self updateRemoteConfig];
}
return self;
} 

- (void)activateDebugMode
{
FIRRemoteConfigSettings *remoteConfigSettings = [[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:YES];
self.remoteConfig.configSettings = remoteConfigSettings;
}

- (void)updateRemoteConfig
{
[self fetchConfigWithCompletionHandler:nil];
}

- (void)fetchConfigWithCompletionHandler:  (FireBaseConfigCompletionHandler)completionHandler
{
NSTimeInterval cacheExpiration = 43200;
BOOL debug = ConfigurationValue(DebugMode);
if (debug) {
    cacheExpiration = 0;
    [self activateDebugMode];
}

[self.remoteConfig fetchWithExpirationDuration:cacheExpiration completionHandler:^(FIRRemoteConfigFetchStatus status, NSError * _Nullable error) {
    if (status == FIRRemoteConfigFetchStatusSuccess) {
        NSLog(@"Config fetched!");
        [self.remoteConfig activateFetched];
        // do smth
    } else {
        NSLog(@"Config not fetched");
        NSLog(@"Error %@", error.localizedDescription);
    }
}];
}

Even I use fetchWithCompletionHandler without cacheExpriration parameter, it also doesn't work. Setting remoteConfigSettings in debugMode = FALSE doesn't work either. I created a small test app with the same code and it works! The only difference us that I can see is "Enable Modules" parameter in Built Settings. What am I doing wrong? Thank you in advance!

Pseudohermaphroditism answered 16/3, 2018 at 10:15 Comment(6)
HI Tatiana, how are you determining that the data is not coming from the cache?Exedra
I change parameters in Firebase remote console, then launch my app again. I should see the old data (that was loaded the previous time) but I see a newPseudohermaphroditism
If you remove debug mode and set the expiration to 0 the SDK should be throttled after 5 tries, forcing the use of the cache. could you check if you are seeing throttling?Exedra
No, throttling doesn't workPseudohermaphroditism
Did you try setting a high expiration time even in debug mode (I tried it with swift and 3600, even in debug mode, it fetched from the cache)Orv
Typically the behavior you're explaining would only happen if the cache expiration being sent is 0. Are you 100% sure that it isn't sending 0, that the debug variable is actually false, etc?Undeniable
G
0

Sorry, I don't know how to read Objective C code - but looks like when your app runs in debug mode, you set the cacheExpiration to 0.

When cacheExpiration is 0, network will be hit on all requests. This is meant to aid local development workflows. I would suggest retrying this code with a larger value of cacheExpiration

Please see https://firebase.google.com/docs/remote-config/android#caching_and_throttling

Goldina answered 6/4, 2018 at 18:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.