Method: SuperSettings::LocalCache#refresh

Defined in:
lib/super_settings/local_cache.rb

#refresh(asynchronous = false) ⇒ void

This method returns an undefined value.

Load only settings that have changed since the last load.

Parameters:

  • asynchronous (Boolean) (defaults to: false)

    whether to refresh settings in a background thread



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/super_settings/local_cache.rb', line 146

def refresh(asynchronous = false)
  last_refresh_time = @last_refreshed
  return if last_refresh_time.nil?
  return if @refreshing

  @lock.synchronize do
    return if @refreshing

    @next_check_at = Time.now + @refresh_interval
    return if @cache.empty?

    @refreshing = true
  end

  refresh_block = lambda do
    begin
      last_db_update = Setting.last_updated_at
      if last_db_update.nil? || last_db_update >= last_refresh_time - 1
        merge_load(last_refresh_time)
      end
    ensure
      @refreshing = false
    end
  end

  if asynchronous
    Thread.new(&refresh_block)
  else
    refresh_block.call
  end
end