从 MyBatis 缓存中移除特定的 select id 数据

Remove specific select id data from MyBatis cache

<mapper namespace="src.main.domain.EqMapper">
    <cache eviction="FIFO" size="512" readOnly="true"/>

    <select id="getStoreIdAndEqId" resultType="String" flushCache="false" useCache="true">
        select count(author) from blog
    </select>
    <select id="getWholeData" resultType="java.util.LinkedHashMap" flushCache="false" useCache="true">
        select * from blog
    </select>
</mapper>

Configuration configuration = MyBatisUtil.getSqlSessionFactory().getConfiguration(); 
Collection<Cache> caches = configuration.getCaches(); 
for (Cache cache : caches) { 
    Lock w = cache.getReadWriteLock().writeLock(); 
    w.lock(); 
    try { 
        cache.clear(); 
    } finally { 
        w.unlock(); 
    } 
} 

以上缓存逻辑清空所有缓存。是否可以清除特定缓存?我想删除 getStoreIdAndEqId 缓存而不是 getWholeData 缓存。

试试这个:

<select id="getStoreIdAndEqId" resultType="String" flushCache="true" useCache="false">
     select count(author) from blog
</select>
<select id="getWholeData" resultType="java.util.LinkedHashMap" flushCache="false" useCache="true">
     select * from blog
</select>