Class: CacheFlow

Inherits:
Object
  • Object
show all
Defined in:
lib/cache-flow.rb

Constant Summary collapse

TIME_ZONE =

Put all these constants into a configurable setting hash

"Pacific Time (US & Canada)"
HOUR_RANGE_START =

Hour based on 24 hour clock

1
HOUR_RANGE_END =
4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frequency = "daily") ⇒ CacheFlow

Returns a new instance of CacheFlow.



12
13
14
# File 'lib/cache-flow.rb', line 12

def initialize(frequency = "daily")
  self.frequency = frequency
end

Instance Attribute Details

#frequencyObject

Returns the value of attribute frequency.



10
11
12
# File 'lib/cache-flow.rb', line 10

def frequency
  @frequency
end

Instance Method Details

#generate_expiryObject



16
17
18
19
20
21
22
# File 'lib/cache-flow.rb', line 16

def generate_expiry
  # Rails :expires_in accepts seconds from now to expire the key in
  case frequency
  when "daily"
    random_time_in_range(24.hours.from_now)
  end
end

#random_time_in_range(day_to_bust) ⇒ Object



24
25
26
27
28
29
# File 'lib/cache-flow.rb', line 24

def random_time_in_range(day_to_bust)
  time_to_bust = day_to_bust.in_time_zone(TIME_ZONE).beginning_of_day
  range_start = time_to_bust + HOUR_RANGE_START.hours
  range_end = time_to_bust + HOUR_RANGE_END.hours
  rand(range_start.to_i..range_end.to_i) - Time.now.to_i
end