jnunemaker/mongomapper — pull request #408 by brianhempel (2012-04-18 03:13:03+00:00)
Title: Thread-safe identity-map via Thread.current [Fixes #181]

Uses a per-thread key in `Thread.current` so that each thread gets its own identity maps.

``` ruby
class Post
include MongoMapper::Document
plugin MongoMapper::Plugins::IdentityMap

key :name
end

Post.identity_map_scope_key # => "mongo_mapper_Post2160085000_identity_map"

bear = Post.create(:name => "Bear")

Post.identity_map.keys # => [BSON::ObjectId('4f8e2ee278fca26842000001')]

t = Thread.new do
Post.identity_map.keys # => []
bear.save
Post.identity_map.keys # => [BSON::ObjectId('4f8e2ee278fca26842000001')]
MongoMapper::Plugins::IdentityMap.clear
Post.identity_map.keys # => []
end

t.join

Post.identity_map.keys # => [BSON::ObjectId('4f8e2ee278fca26842000001')]
```

Identity map configuration (on/off) is still global.