My observation about ruby and transactions, started an interesting discussion (see also Funny reaction in RoR space to comment about transactions, The cure for RoR Active Record and transactions). The problem here: in RoR multiple instances of a persistent object with the same PK can exist in the SAME transaction, which can lead to inconsistencies, or you have to deal with optimistic concurrency INSIDE a transaction (which is funny).
As a reaction, Simon Harris provided an implementation of a RoR plugin with the IdentityMap implementation, which solves the problem of stale objects. The implementation is lean, and can be provided, without changing the RoR frameworks (which speaks for extendibility of RoR).
IdentityMap only solves the problem, in case you are only working with the instances inside a transaction. You should not access/change the database directly, because then your transactional cache (the identity map) would become inconsistent. If you like also to work with the database, a robust invalidation mechanism is needed.
In case you have already an IdentityMap, why you would like to invoke save()? Wouldn't it be cleaner to store automatically all contents of the IdentityMap at the end of transaction automatically?
Web Apps, SPA, PWA with vanilla Java Script (ES 6+), CSS 3 and WebStandards only. As simple as possible, but not simpler. See you at: (Progressive) Web apps, Single Page Apps and WebStandards airhacks workshops at MUC airport, Winter Edition
airhacks.fm the podcast:
Stay in touch: airhacks.news.