Class: CacheFlow
- Inherits:
-
Object
- Object
- CacheFlow
- Defined in:
- lib/cache-flow/cache-flow.rb,
lib/cache-flow/configuration.rb
Defined Under Namespace
Classes: Configuration
Class Attribute Summary collapse
-
.configuration ⇒ Object
Configure CacheFlow in your initializers: example file location: config/initializers/cache_flow.rb example code: CacheFlow.configure do |config| config.default_options = { time_zone: “Eastern Time (US & Canada)”, hour_range_start: 17, hour_range_end: 20 } end.
Instance Attribute Summary collapse
-
#frequency ⇒ Object
Returns the value of attribute frequency.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #generate_expiry ⇒ Object
-
#initialize(frequency = "daily", options = {}) ⇒ CacheFlow
constructor
A new instance of CacheFlow.
- #random_time_in_range(day_to_bust) ⇒ Object
Constructor Details
#initialize(frequency = "daily", options = {}) ⇒ CacheFlow
Returns a new instance of CacheFlow.
5 6 7 8 |
# File 'lib/cache-flow/cache-flow.rb', line 5 def initialize(frequency = "daily", = {}) @options = CacheFlow.configuration..merge() @frequency = frequency end |
Class Attribute Details
.configuration ⇒ Object
Configure CacheFlow in your initializers: example file location: config/initializers/cache_flow.rb example code: CacheFlow.configure do |config|
config. = {
time_zone: "Eastern Time (US & Canada)",
hour_range_start: 17,
hour_range_end: 20
}
end
31 32 33 |
# File 'lib/cache-flow/configuration.rb', line 31 def configuration @configuration end |
Instance Attribute Details
#frequency ⇒ Object
Returns the value of attribute frequency.
2 3 4 |
# File 'lib/cache-flow/cache-flow.rb', line 2 def frequency @frequency end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/cache-flow/cache-flow.rb', line 3 def @options end |
Class Method Details
.configure {|configuration| ... } ⇒ Object
35 36 37 |
# File 'lib/cache-flow/configuration.rb', line 35 def self.configure yield(configuration) end |
Instance Method Details
#generate_expiry ⇒ Object
10 11 12 13 14 15 16 |
# 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) ⇒ Object
18 19 20 21 22 23 |
# 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([: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 |