Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunitySumbit a ticketLog In
GitHubNuGetDev CommunitySumbit a ticket
These docs are for v2.0. Click to read the latest docs for v3.0.

Configure datafile polling

During its initialization, the manager attempts to pull the newest datafile from the CDN servers. After this, the Optimizely manager can periodically check for and pull a new datafile at the time interval you set during its initialization. The process of checking for and downloading a new datafile is called datafile polling.

By default, the manager only checks for a new datafile during initialization. To enable periodic datafile polling, you must define a polling interval when building the manager. This value is the number of seconds the manager waits between datafile polling attempts.

// Poll every 2 minutes
OptimizelyManager optimizelyManager = OptimizelyManager.builder()
  .withSDKKey("SDK_KEY_HERE")
  .withDatafileDownloadInterval(60L * 2L)
  .build(getApplicationContext());
OPTLYDatafileManagerDefault *datafileManager = [[OPTLYDatafileManagerDefault alloc] initWithBuilder:[OPTLYDatafileManagerBuilder builderWithBlock:^(OPTLYDatafileManagerBuilder * _Nullable builder) {
  builder.datafileConfig = [[OPTLYDatafileConfig alloc] initWithProjectId:nil withSDKKey:@"SDK_KEY_HERE"];
  builder.datafileFetchInterval = 120.0;
}]];
// Build a manager
OPTLYManager *manager = [[OPTLYManager alloc] initWithBuilder:[OPTLYManagerBuilder  builderWithBlock:^(OPTLYManagerBuilder * _Nullable builder) {
  builder.sdkKey = @"SDK_KEY_HERE";
  builder.datafileManager = datafileManager;
}]];
// ---- Create the Datafile Manager ----
let datafileManager = OPTLYDatafileManagerDefault(builder:      OPTLYDatafileManagerBuilder(block: { (builder) in
  builder!.datafileFetchInterval =   TimeInterval(self.datafileManagerDownloadInterval)
  builder!.datafileConfig = OPTLYDatafileConfig(projectId: nil, withSDKKey:"SDK_KEY_HERE")!;
}))

let builder = OPTLYManagerBuilder(block: { (builder) in
  builder!.projectId = nil;
  builder!.sdkKey = "SDK_KEY_HERE"
  builder!.datafileManager = datafileManager!
  builder!.eventDispatcher = eventDispatcher
})

// ---- Create the Manager ----
var optimizelyManager = OPTLYManager(builder: builder)

Usage notes

  • In Android, the minimum polling interval is 60 seconds. In iOS, the minimum polling interval is 2 minutes while the app is open. If you specify shorter polling intervals than these minimums, the SDK will automatically reset the intervals to 60 seconds (Android) or 2 minutes (iOS).

  • Updated datafiles do not take effect until your app is restarted or when you re-initialize the Optimizely manager. This implementation strategy allows the data to change while the app is running without causing nondeterministic behavior.

  • The Optimizely manager only checks for new datafiles when the SDK is active and the app is running. Datafile polling is never done while the app is in the background.

Android

To override the default datafile handler and use your own, implement DatafileHandler.