Class DataMapper::IdentityMap
In: lib/data_mapper/identity_map.rb
lib/data_mapper/identity_map.rb
Parent: Object

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

Methods

clear!   clear!   delete   delete   get   get   new   new   set   set  

Public Class methods

[Source]

    # File lib/data_mapper/identity_map.rb, line 7
 7:     def initialize
 8:       # WeakHash is much more expensive, and not necessary if the IdentityMap is tied to Session instead of Database.
 9:       # @cache = Hash.new { |h,k| h[k] = Support::WeakHash.new }
10:       @cache = Hash.new { |h,k| h[k] = Hash.new }
11:     end

[Source]

    # File lib/data_mapper/identity_map.rb, line 7
 7:     def initialize
 8:       # WeakHash is much more expensive, and not necessary if the IdentityMap is tied to Session instead of Database.
 9:       # @cache = Hash.new { |h,k| h[k] = Support::WeakHash.new }
10:       @cache = Hash.new { |h,k| h[k] = Hash.new }
11:     end

Public Instance methods

Clears a particular set of classes from the IdentityMap.

[Source]

    # File lib/data_mapper/identity_map.rb, line 34
34:     def clear!(klass)
35:       @cache.delete(klass)
36:     end

Clears a particular set of classes from the IdentityMap.

[Source]

    # File lib/data_mapper/identity_map.rb, line 34
34:     def clear!(klass)
35:       @cache.delete(klass)
36:     end

Remove an instance from the IdentityMap.

[Source]

    # File lib/data_mapper/identity_map.rb, line 29
29:     def delete(instance)
30:       @cache[mapped_class(instance.class)].delete(instance.key)
31:     end

Remove an instance from the IdentityMap.

[Source]

    # File lib/data_mapper/identity_map.rb, line 29
29:     def delete(instance)
30:       @cache[mapped_class(instance.class)].delete(instance.key)
31:     end

Pass a Class and a key, and to retrieve an instance. If the instance isn‘t found, nil is returned.

[Source]

    # File lib/data_mapper/identity_map.rb, line 15
15:     def get(klass, key)
16:       @cache[mapped_class(klass)][key]
17:     end

Pass a Class and a key, and to retrieve an instance. If the instance isn‘t found, nil is returned.

[Source]

    # File lib/data_mapper/identity_map.rb, line 15
15:     def get(klass, key)
16:       @cache[mapped_class(klass)][key]
17:     end

Pass an instance to add it to the IdentityMap. The instance must have an assigned key.

[Source]

    # File lib/data_mapper/identity_map.rb, line 21
21:     def set(instance)
22:       instance_key = instance.key
23:       raise "Can't store an instance with a nil key in the IdentityMap" if instance_key.nil?
24:       
25:       @cache[mapped_class(instance.class)][instance_key] = instance
26:     end

Pass an instance to add it to the IdentityMap. The instance must have an assigned key.

[Source]

    # File lib/data_mapper/identity_map.rb, line 21
21:     def set(instance)
22:       instance_key = instance.key
23:       raise "Can't store an instance with a nil key in the IdentityMap" if instance_key.nil?
24:       
25:       @cache[mapped_class(instance.class)][instance_key] = instance
26:     end

[Validate]