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.



69
70
71
72
# File 'lib/test_prof/any_fixture.rb', line 69

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

Instance Attribute Details

#statsObject (readonly)

Returns the value of attribute stats.



67
68
69
# File 'lib/test_prof/any_fixture.rb', line 67

def stats
  @stats
end

#storeObject (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

#clearObject



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