Class: DB::Model::Cache
- Inherits:
-
Object
- Object
- DB::Model::Cache
- Defined in:
- lib/db/model/cache.rb
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #fetch(key) ⇒ Object
-
#initialize ⇒ Cache
constructor
A new instance of Cache.
- #inspect ⇒ Object
- #size ⇒ Object
- #update(key, records) ⇒ Object
Constructor Details
#initialize ⇒ Cache
Returns a new instance of Cache.
12 13 14 15 |
# File 'lib/db/model/cache.rb', line 12 def initialize @relations = {} @records = {} end |
Instance Method Details
#empty? ⇒ Boolean
17 18 19 |
# File 'lib/db/model/cache.rb', line 17 def empty? @relations.empty? end |
#fetch(key) ⇒ Object
25 26 27 28 29 |
# File 'lib/db/model/cache.rb', line 25 def fetch(key) @relations.fetch(key) do deduplicate(yield) end end |
#inspect ⇒ Object
35 36 37 |
# File 'lib/db/model/cache.rb', line 35 def inspect "\#<#{self.class} #{@relations.size} relations; #{@records.size} records>" end |
#size ⇒ Object
21 22 23 |
# File 'lib/db/model/cache.rb', line 21 def size @relations.size end |
#update(key, records) ⇒ Object
31 32 33 |
# File 'lib/db/model/cache.rb', line 31 def update(key, records) @relations[key] = records end |