iBatis(MyBatis)开启缓存后,通过外部程序修改或者删除数据库记录,如何让Cache清除?5
再简单的描述一下(假设数据库系统为MySQL),例如有一个Java的应用持久层框架是使用iBatis(MyBatis)有一个每个500ms(毫秒)调用一次对数据库中ID为100的记录进行 select 操作,由于缓存的时间很长,此时有一个外部程序,假设此程序为一个C/C++程序通过mysql C API 连接到当前数据库(和java应用程序同一个数据库)它将ID为100的记录删除了。然而此时java应用中每个500ms对此记录进行select 操作依然有效!这个很郁闷,iBatis(MyBatis)的缓存有什么选项能够对外部数据库连接对记录进行修改或者删除能让iBatis(MyBatis)主动清除缓存?
官方文档摘要
MyBatis SqlSession provides you with specific methods to handle transactions programmatically. But when using MyBatis-Spring your beans will be injected with a Spring managed SqlSession or a Spring managed mapper. That means that Spring will always handle your transactions.
You cannot call SqlSession.commit(), SqlSession.rollback() or SqlSession.close() over a Spring managed SqlSession. If you try to do so, a UnsupportedOperationException exception will be thrown. Note these methods are not exposed in injected mapper classes.