Module: Suggester::Handlers::Helpers::Refresh

Included in:
Base
Defined in:
lib/suggester/handlers/helpers/refresh.rb

Instance Method Summary collapse

Instance Method Details

#force_refresh!Object



12
13
14
# File 'lib/suggester/handlers/helpers/refresh.rb', line 12

def force_refresh!
  @last_refreshed_at = nil
end

#last_refreshed_atObject



30
31
32
# File 'lib/suggester/handlers/helpers/refresh.rb', line 30

def last_refreshed_at
  @last_refreshed_at
end

#needs_refresh?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/suggester/handlers/helpers/refresh.rb', line 16

def needs_refresh?
  return true if last_refreshed_at.nil?
  refresh_interval && last_refreshed_at + refresh_interval.minutes < Time.now
end

#refresh!Object



6
7
8
9
10
# File 'lib/suggester/handlers/helpers/refresh.rb', line 6

def refresh!
  # assumption: assignment is atomic in ruby
  @cache = build_cache
  @last_refreshed_at = Time.now
end

#refresh_intervalObject



21
22
23
# File 'lib/suggester/handlers/helpers/refresh.rb', line 21

def refresh_interval
  @refresh_interval
end

#refresh_interval=(value) ⇒ Object



25
26
27
28
# File 'lib/suggester/handlers/helpers/refresh.rb', line 25

def refresh_interval=(value)
  @refresh_interval = value
  @refresh_interval = @refresh_interval.to_i unless value.nil?
end