Do not use cache data after commit
After a commit, the data read out of the database are no more linked to the start of the transaction but from the last commit.
So when we do a commit inside a loop, the cache of the records may not more be valid.