Class: Polyrun::Data::CachedFixtures::Cache
- Inherits:
-
Object
- Object
- Polyrun::Data::CachedFixtures::Cache
- Defined in:
- lib/polyrun/data/cached_fixtures.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #clear ⇒ Object
- #fetch(key, &block) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #stats_snapshot ⇒ Object
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
17 18 19 20 |
# File 'lib/polyrun/data/cached_fixtures.rb', line 17 def initialize @store = {} @stats = {} end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
15 16 17 |
# File 'lib/polyrun/data/cached_fixtures.rb', line 15 def store @store end |
Instance Method Details
#clear ⇒ Object
38 39 40 41 |
# File 'lib/polyrun/data/cached_fixtures.rb', line 38 def clear store.clear @stats.clear end |
#fetch(key, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/polyrun/data/cached_fixtures.rb', line 22 def fetch(key, &block) k = key.to_s if store.key?(k) @stats[k][:hits] += 1 return store[k] end t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC) store[k] = yield @stats[k] = { build_time: Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0, hits: 0 } store[k] end |
#stats_snapshot ⇒ Object
43 44 45 |
# File 'lib/polyrun/data/cached_fixtures.rb', line 43 def stats_snapshot @stats.transform_values(&:dup) end |