Class: ConfigCat::ConfigCatClient
- Inherits:
-
Object
- Object
- ConfigCat::ConfigCatClient
- Defined in:
- lib/configcat/configcatclient.rb
Instance Method Summary collapse
- #force_refresh ⇒ Object
- #get_all_keys ⇒ Object
- #get_value(key, default_value, user = nil) ⇒ Object
-
#initialize(api_key, poll_interval_seconds: 60, max_init_wait_time_seconds: 5, on_configuration_changed_callback: nil, cache_time_to_live_seconds: 60, config_cache_class: nil, base_url: nil) ⇒ ConfigCatClient
constructor
A new instance of ConfigCatClient.
- #stop ⇒ Object
Constructor Details
#initialize(api_key, poll_interval_seconds: 60, max_init_wait_time_seconds: 5, on_configuration_changed_callback: nil, cache_time_to_live_seconds: 60, config_cache_class: nil, base_url: nil) ⇒ ConfigCatClient
Returns a new instance of ConfigCatClient.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/configcat/configcatclient.rb', line 11 def initialize(api_key, poll_interval_seconds:60, max_init_wait_time_seconds:5, on_configuration_changed_callback:nil, cache_time_to_live_seconds:60, config_cache_class:nil, base_url:nil) if api_key === nil raise ConfigCatClientException, "API Key is required." end @_api_key = api_key if config_cache_class @_config_cache = config_cache_class.new() else @_config_cache = InMemoryConfigCache.new() end if poll_interval_seconds > 0 @_config_fetcher = CacheControlConfigFetcher.new(api_key, "p", base_url) @_cache_policy = AutoPollingCachePolicy.new(@_config_fetcher, @_config_cache, poll_interval_seconds, max_init_wait_time_seconds, on_configuration_changed_callback) else if cache_time_to_live_seconds > 0 @_config_fetcher = CacheControlConfigFetcher.new(api_key, "l", base_url) @_cache_policy = LazyLoadingCachePolicy.new(@_config_fetcher, @_config_cache, cache_time_to_live_seconds) else @_config_fetcher = CacheControlConfigFetcher.new(api_key, "m", base_url) @_cache_policy = ManualPollingCachePolicy.new(@_config_fetcher, @_config_cache) end end end |
Instance Method Details
#force_refresh ⇒ Object
59 60 61 |
# File 'lib/configcat/configcatclient.rb', line 59 def force_refresh() @_cache_policy.force_refresh() end |
#get_all_keys ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/configcat/configcatclient.rb', line 51 def get_all_keys() config = @_cache_policy.get() if config === nil return [] end return config.keys end |
#get_value(key, default_value, user = nil) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/configcat/configcatclient.rb', line 43 def get_value(key, default_value, user=nil) config = @_cache_policy.get() if config === nil return default_value end return RolloutEvaluator.evaluate(key, user, default_value, config) end |
#stop ⇒ Object
63 64 65 66 |
# File 'lib/configcat/configcatclient.rb', line 63 def stop() @_cache_policy.stop() @_config_fetcher.close() end |