Class: DB::Model::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/db/model/cache.rb

Instance Method Summary collapse

Constructor Details

#initializeCache

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

Returns:

  • (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

#inspectObject



35
36
37
# File 'lib/db/model/cache.rb', line 35

def inspect
  "\#<#{self.class} #{@relations.size} relations; #{@records.size} records>"
end

#sizeObject



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