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.
69 70 71 72 |
# File 'lib/test_prof/any_fixture.rb', line 69 def initialize @store = {} @stats = {} end |
Instance Attribute Details
#stats ⇒ Object (readonly)
Returns the value of attribute stats.
67 68 69 |
# File 'lib/test_prof/any_fixture.rb', line 67 def stats @stats end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
67 68 69 |
# File 'lib/test_prof/any_fixture.rb', line 67 def store @store end |
Instance Method Details
#clear ⇒ Object
88 89 90 91 |
# File 'lib/test_prof/any_fixture.rb', line 88 def clear store.clear stats.clear end |
#fetch(key) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/test_prof/any_fixture.rb', line 74 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 |