Hi Brent,

> With the Identity Map pattern, I thought I wouldn't have this problem  
> -- I thought that this would be true:
>
>      Player.get(1).object_id == Player.get(1).object_id
>
> Not so. I found that I had to do something like this:
>
>      repository(:default) do
>           Player.get(1).object_id == Player.get(1).object_id
>      end

Think of the Identity Map as a Hash that maps each key to a Resource.
Whenever DataMapper looks up a Resource by a key it checks the
Identity Map first to see if it's already been loaded, reusing it if
it has, otherwise loading the Resource and registering it in the
Identity Map to speed future lookups.

The reason why this doesn't happen globally is because it would have
very negative effects for a long running processes.  The reference to
the Resource object from the IM would never be freed, thus preventing
them from ever being garbage collected.  Memory usage for the process
would continue to grow until it consumed all available memory.

Instead what we do is make it so the Identity Map is only in scope
during the repository block.  This allows proper GC to occur, and
works well with long running processes.

It may be possible to implement a "global" Identity Map if ruby had a
decent WeakHash library.  The idea being that if we used a WeakHash
instead of a Hash, Ruby would be able to GC Resource objects where the
only remaining reference is from the IM.  However in speaking with
Sam, the WeakHash libraries he's tried never worked properly.  I don't
know all the details, you'll have to ask Sam for those. The only thing
I know is it didn't work as expected.

If you're willing to fix and/or create a working WeakHash library for
Ruby I'd be interested in looking into a global IM further.  My
primary concern is that it work correctly and be at least comparable
in speed to the current IM system which is based on a Ruby Hash.  A
global IM would likely need to be a plugin rather than replacing
what's in dm-core because it will need alot of testing and what we
already have is relatively safe and well proven.

Dan
(dkubb)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to