Class: ProconBypassMan::Procon::FlipCache

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/procon/flip_cache.rb

Class Method Summary collapse

Class Method Details

.fetch(key:, expires_in:, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/procon_bypass_man/procon/flip_cache.rb', line 3

def self.fetch(key: , expires_in: , &block)
  if expires_in.nil?
    block.call
  else
    @@previous_flips_at_table[key] ||= Time.now
    if @@previous_flips_at_table[key] < Time.now
      @@previous_flips_at_table[key] = Time.now + expires_in
      block.call
    end
  end
end

.reset!Object

for testing



16
17
18
# File 'lib/procon_bypass_man/procon/flip_cache.rb', line 16

def self.reset!
  @@previous_flips_at_table = {}
end