Class: TestProf::AnyFixture::Cache
- Inherits:
-
Object
- Object
- TestProf::AnyFixture::Cache
- Defined in:
- lib/test_prof/any_fixture.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#stats ⇒ Object
readonly
Returns the value of attribute stats.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #clear ⇒ Object
- #fetch(key) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
Constructor Details
#initialize ⇒ Cache
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
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
13 14 15 |
# File 'lib/test_prof/any_fixture.rb', line 13 def stats @stats end |
#store ⇒ Object (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
#clear ⇒ Object
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 |