Polling Modes

The ConfigCat SDK supports 3 different polling mechanisms to acquire the setting values from ConfigCat. After latest setting values are downloaded, they are stored in the internal cache then all requests are served from there. With the following polling modes, you can customize the SDK to best fit to your application's lifecycle.

Auto polling (default)

The ConfigCat SDK downloads the latest values and stores them automatically every 60 seconds.

Use the the autoPollIntervalInSeconds option parameter of the AutoPollingPolicy to change the polling interval.

Lazy loading

When calling getValue() the ConfigCat SDK downloads the latest setting values if they are not present or expired in the cache. In this case the getValue() will return the setting value after the cache is updated.

Use the cacheRefreshIntervalInSeconds option parameter of the LazyLoadingPolicy to set cache lifetime.

Use the asyncRefresh option parameter of the LazyLoadingPolicy to define how do you want to handle the expiration of the cached configuration. If you choose asynchronous refresh then when a request is being made on the cache while it's expired, the previous value will be returned immediately until the fetching of the new configuration is completed.

Custom policy

You can also implement your custom refresh policy by extending the RefreshPolicy abstract class.

publicclassMyCustomPolicyextendsRefreshPolicy{publicMyCustomPolicy(ConfigFetcher configFetcher,ConfigCache cache){super(configFetcher, cache);}@OverridepublicCompletableFuture<String>getConfigurationJsonAsync(){// this method will be called when the configuration is requested from the ConfigCatClient.// you can access the config fetcher through the super.fetcher() and the internal cache via super.cache()}// optional, in case if you have any resources that should be closed@Overridepublicvoidclose()throwsIOException{super.close();// here you can close your resources}}

If you decide to override the close() method, you should also call the super.close() to tear the cache appropriately down.

Then you can simply inject your custom policy implementation into the ConfigCatClient:

Custom cache

You have the option to inject your custom cache implementation into the client. All you have to do is to inherit from the ConfigCache abstract class:

publicclassMyCustomCacheextendsConfigCache{@OverridepublicStringread(){// here you have to return with the cached value// you can access the latest cached value in case // of a failure like: super.inMemoryValue();}@Overridepublicvoidwrite(String value){// here you have to store the new value in the cache}}

HttpClient

The ConfigCat SDK internally uses an OkHttpClient instance to fetch the latest configuration over HTTP. You have the option to override the internal Http client with your customized one. For example if your application runs behind a proxy you can do the following: