Class: HatiConfig::Cache::RefreshConfig

Inherits:
Object
  • Object
show all
Includes:
NumericConfigurable
Defined in:
lib/hati_config/cache.rb

Overview

RefreshConfig class handles refresh configuration and behavior.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NumericConfigurable

included

Constructor Details

#initialize ⇒ RefreshConfig

Returns a new instance of RefreshConfig.



152
153
154
155
156
# File 'lib/hati_config/cache.rb', line 152

def initialize
  @interval = 60
  @jitter = 0
  @backoff_config = BackoffConfig.new
end

Instance Attribute Details

#backoff_config ⇒ Object (readonly)

Returns the value of attribute backoff_config.



148
149
150
# File 'lib/hati_config/cache.rb', line 148

def backoff_config
  @backoff_config
end

#interval ⇒ Object (readonly)

Returns the value of attribute interval.



148
149
150
# File 'lib/hati_config/cache.rb', line 148

def interval
  @interval
end

#jitter ⇒ Object (readonly)

Returns the value of attribute jitter.



148
149
150
# File 'lib/hati_config/cache.rb', line 148

def jitter
  @jitter
end

Instance Method Details

#backoff { ... } ⇒ Object

Configures backoff behavior.

Yields:

  • The backoff configuration block



161
162
163
164
# File 'lib/hati_config/cache.rb', line 161

def backoff(&block)
  @backoff_config.instance_eval(&block) if block_given?
  @backoff_config
end

#next_refresh_time ⇒ Time

Gets the next refresh time.

Returns:

  • (Time) —

    The next refresh time



169
170
171
172
# File 'lib/hati_config/cache.rb', line 169

def next_refresh_time
  jitter_amount = jitter.positive? ? rand(0.0..jitter) : 0
  Time.now + interval + jitter_amount
end