Class: TestProf::AnyFixture::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/test_prof/any_fixture.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCache

Returns a new instance of Cache.



15
16
17
18
# File 'lib/test_prof/any_fixture.rb', line 15

def initialize
  @store = {}
  @stats = {}
end

Instance Attribute Details

#statsObject (readonly)

Returns the value of attribute stats.



13
14
15
# File 'lib/test_prof/any_fixture.rb', line 13

def stats
  @stats
end

#storeObject (readonly)

Returns the value of attribute store.



13
14
15
# File 'lib/test_prof/any_fixture.rb', line 13

def store
  @store
end

Instance Method Details

#clearObject



34
35
36
37
# File 'lib/test_prof/any_fixture.rb', line 34

def clear
  store.clear
  stats.clear
end

#fetch(key) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/test_prof/any_fixture.rb', line 20

def fetch(key)
  if store.key?(key)
    stats[key][:hit] += 1
    return store[key]
  end

  return unless block_given?

  ts = TestProf.now
  store[key] = yield
  stats[key] = { time: TestProf.now - ts, hit: 0 }
  store[key]
end