示例sql:
@Transactional
public RebateContract getInfo(RebateContract contract) {
RebateContract rebContractInfo = rebateContractDao.getInfo(contract);
logger.info("agentId:" + rebContractInfo.getAgentId());
rebContractInfo.setAgentId(10000L);
// 不会再查问 而是从缓存中获取rebContractInfo的值
RebateContract rebContractInfo1 = rebateContractDao.getInfo(contract);
logger.info("agentId1:" + rebContractInfo1.getAgentId());
return rebContractInfo1;
}
执行后果:
留神:必须同一个事物中
同一个事务中查问一次后,间接修复查问后后果,再次雷同sql查问,理论不会再查问,而是从缓存中获取上次的查问后果。
但上次查问后果曾经被批改,所以前面查问获取到的值已与理论查问该获取的值不一样了。
发表回复