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.



29
30
31
32
# File 'lib/db/model/cache.rb', line 29

def initialize
	@relations = {}
	@records = {}
end

Instance Method Details

#empty?Boolean

Returns:

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

#inspectObject



52
53
54
# File 'lib/db/model/cache.rb', line 52

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

#sizeObject



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