2

If two transactions (both at RR isolation level) ask for the same item which is 2nd-level cached, and then they modify and store this item. Now, for reading that item, they did not run any SQL because it's cached; so in this case, will they actually start a data base transaction? And when they commit their changes, will they run into lost update problem?

4

1 回答 1

1

从悲观的角度来看:

如果二级缓存被配置为参与事务,那么只有第一个获得写锁的缓存才能修改缓存对象,然后将更改写入数据库。当第二个事务想要获取写锁时,它必须等到第一个事务结束并释放它。

使用乐观锁定,我猜应该会发生并发修改异常(或类似名称),并且第二个事务将重试操作。

于 2012-04-05T14:25:47.187 回答