class CacheFlow

Attributes

configuration[RW]
frequency[RW]
options[R]

Public Class Methods

configure() { |configuration| ... } click to toggle source
# File lib/cache-flow/configuration.rb, line 35
def self.configure
  yield(configuration)
end
new(frequency = "daily", options = {}) click to toggle source
# File lib/cache-flow/cache-flow.rb, line 5
def initialize(frequency = "daily", options = {})
  @options = CacheFlow.configuration.default_options.merge(options)
  @frequency = frequency
end

Public Instance Methods

generate_expiry() click to toggle source
# File lib/cache-flow/cache-flow.rb, line 10
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) click to toggle source
# File lib/cache-flow/cache-flow.rb, line 18
def random_time_in_range(day_to_bust)
  time_to_bust = day_to_bust.in_time_zone(options[:time_zone]).beginning_of_day
  range_start = time_to_bust + options[:hour_range_start].hours
  range_end = time_to_bust + options[:hour_range_end].hours
  rand(range_start.to_i..range_end.to_i) - Time.now.to_i
end