ConfigCat.CachePolicy (ConfigCat v2.0.0) View Source
Represents the polling mode used by ConfigCat.
The ConfigCat SDK supports 3 different polling mechanisms to acquire the setting values from ConfigCat. After the latest setting values are downloaded, they are stored in the internal cache and 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 on a regular schedule.
See auto/1
below for details.
Lazy loading
When calling any of the public API functions (like get_value()
),
the ConfigCat SDK downloads the latest setting values if they are
not present or have expired. In this case the function will wait
until the settings have been fetched before returning.
See lazy/1
below for details.
Manual polling
Manual polling gives you full control over when the setting
values are downloaded. ConfigCat SDK will not update them
automatically. Calling ConfigCat.force_refresh/1
is your
application's responsibility.
See manual/0
below for details.
Link to this section Summary
Types
Options for auto-polling mode.
Options for lazy-polling mode.
Callback to call when configuration changes.
The polling mode
Link to this section Types
Specs
auto_options() :: [ on_changed: on_changed_callback(), poll_interval_seconds: pos_integer() ]
Options for auto-polling mode.
Specs
lazy_options() :: [{:cache_expiry_seconds, non_neg_integer()}]
Options for lazy-polling mode.
Specs
on_changed_callback() :: (() -> :ok)
Callback to call when configuration changes.
Specs
t()
The polling mode
Link to this section Functions
Specs
auto(auto_options()) :: t()
Auto-polling mode.
The ConfigCat SDK downloads the latest values and stores them automatically on a regular schedule.
Use the poll_interval_seconds
option to change the
polling interval. Defaults to 60 seconds if not specified.
ConfigCat.CachePolicy.auto(poll_interval_seconds: 60)
If you want your application to be notified whenever a new
configuration is available, provide a 0-arity callback function
using the on_change
option.
The on_change
callback is called asynchronously (using Task.start
).
Any exceptions raised are caught and logged.
ConfigCat.CachePolicy.auto(on_changed: callback)
Specs
lazy(lazy_options()) :: t()
Lazy polling mode.
When calling any of the public API functions (like get_value()
),
the ConfigCat SDK downloads the latest setting values if they are
not present or have expired. In this case the function will wait
until the settings have been fetched before returning.
Use the required cache_expiry_seconds
option to set the cache
lifetime.
ConfigCat.CachePolicy.lazy(cache_expiry_seconds: 300)
Specs
manual() :: t()
Manual polling mode.
Manual polling gives you full control over when the setting
values are downloaded. ConfigCat SDK will not update them
automatically. Calling ConfigCat.force_refresh/1
is your
application's responsibility.
ConfigCat.CachePolicy.manual()