Class: DataMapper::IdentityMap

Inherits:
Object
  • Object
show all
Defined in:
lib/gems/dm-core-0.9.9/lib/dm-core/identity_map.rb

Overview

Tracks objects to help ensure that each object gets loaded only once. See: www.martinfowler.com/eaaCatalog/identityMap.html

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object (private)



38
39
40
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/identity_map.rb', line 38

def method_missing(method, *args, &block)
  cache.__send__(method, *args, &block)
end

Instance Method Details

#delete(key) ⇒ Object

Remove a resource from the IdentityMap



22
23
24
25
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/identity_map.rb', line 22

def delete(key)
  @second_level_cache.delete(key) if @second_level_cache
  @cache.delete(key)
end

#get(key) ⇒ Object Also known as: []

Get a resource from the IdentityMap



7
8
9
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/identity_map.rb', line 7

def get(key)
  @cache[key] || (@second_level_cache && @second_level_cache.get(key))
end

#set(key, resource) ⇒ Object Also known as: []=

Add a resource to the IdentityMap



14
15
16
17
# File 'lib/gems/dm-core-0.9.9/lib/dm-core/identity_map.rb', line 14

def set(key, resource)
  @second_level_cache.set(key, resource) if @second_level_cache
  @cache[key] = resource
end