Class: DataMapper::IdentityMap
- Inherits:
-
Object
- Object
- DataMapper::IdentityMap
- Defined in:
- 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
-
#delete(key) ⇒ Object
Remove a resource from the IdentityMap.
-
#get(key) ⇒ Object
(also: #[])
Get a resource from the IdentityMap.
-
#set(key, resource) ⇒ Object
(also: #[]=)
Add a resource to the IdentityMap.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
41 42 43 |
# File 'lib/dm-core/identity_map.rb', line 41 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/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/dm-core/identity_map.rb', line 7 def get(key) @cache[key] end |
#set(key, resource) ⇒ Object Also known as: []=
Add a resource to the IdentityMap
14 15 16 17 |
# File '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 |