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
# 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
# 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
Clears a particular set of classes from the IdentityMap.
# 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.
# 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.
# 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.
# 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 an instance to add it to the IdentityMap. The instance must have an assigned key.
# 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.
# 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