Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # solution provided by Eloy Duran
- class API
- def self.get(id)
- new(with_response_data)
- end
- end
- class APIWithIdentityMap < API
- def self.map
- Thread.current[:map][self] ||= {}
- end
- def self.get(id)
- map[id] ||= super
- end
- end
- def session
- Thread.current[:map] = {}
- yield
- ensure
- Thread.current[:map] = nil
- end
- session do
- # logic that performs requests
- end
Add Comment
Please, Sign In to add comment