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