Class: ConfigCat::ManualPollingCachePolicy

Inherits:
CachePolicy
  • Object
show all
Defined in:
lib/configcat/manualpollingcachepolicy.rb

Instance Method Summary collapse

Constructor Details

#initialize(config_fetcher, config_cache, cache_key) ⇒ ManualPollingCachePolicy

Returns a new instance of ManualPollingCachePolicy.



7
8
9
10
11
12
# File 'lib/configcat/manualpollingcachepolicy.rb', line 7

def initialize(config_fetcher, config_cache, cache_key)
  @_config_fetcher = config_fetcher
  @_config_cache = config_cache
  @_cache_key = cache_key
  @_lock = Concurrent::ReadWriteLock.new()
end

Instance Method Details

#force_refreshObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/configcat/manualpollingcachepolicy.rb', line 24

def force_refresh()
  begin
    configuration_response = @_config_fetcher.get_configuration_json()
    if configuration_response.is_fetched()
      configuration = configuration_response.json()
      begin
        @_lock.acquire_write_lock()
        @_config_cache.set(@_cache_key, configuration)
      ensure
        @_lock.release_write_lock()
      end
    end
  rescue StandardError => e
    ConfigCat.logger.error("Double-check your SDK Key at https://app.configcat.com/sdkkey.")
    ConfigCat.logger.error "threw exception #{e.class}:'#{e}'"
    ConfigCat.logger.error "stacktrace: #{e.backtrace}"
  end
end

#getObject



14
15
16
17
18
19
20
21
22
# File 'lib/configcat/manualpollingcachepolicy.rb', line 14

def get()
  begin
    @_lock.acquire_read_lock()
    config = @_config_cache.get(@_cache_key)
    return config
  ensure
    @_lock.release_read_lock()
  end
end

#stopObject



43
44
45
# File 'lib/configcat/manualpollingcachepolicy.rb', line 43

def stop()
  # pass
end