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.
29 30 31 32 |
# File 'lib/db/model/cache.rb', line 29 def initialize @relations = {} @records = {} end |
Instance Method Details
#empty? ⇒ Boolean
34 35 36 |
# File 'lib/db/model/cache.rb', line 34 def empty? @relations.empty? end |
#fetch(key) ⇒ Object
42 43 44 45 46 |
# File 'lib/db/model/cache.rb', line 42 def fetch(key) @relations.fetch(key) do deduplicate(yield) end end |
#inspect ⇒ Object
52 53 54 |
# File 'lib/db/model/cache.rb', line 52 def inspect "\#<#{self.class} #{@relations.size} relations; #{@records.size} records>" end |
#size ⇒ Object
38 39 40 |
# File 'lib/db/model/cache.rb', line 38 def size @relations.size end |
#update(key, records) ⇒ Object
48 49 50 |
# File 'lib/db/model/cache.rb', line 48 def update(key, records) @relations[key] = records end |