Mapper "A" resultMap with reference to mapper "B" statement seems to clear "B" cache

32 views
Skip to first unread message

Ryan Griffith

unread,
Jul 20, 2023, 6:02:45 PM7/20/23
to mybatis-user
I have 2 mapper XML files, A and B. In one of the files (A) one of the associations in a resultMap references a statement in another mapper's (B) mapping.

I'm using Level 2 cache with the tag <cache flushInterval="60000"/>

Mapper B contains no insert / update / delete statements, so there should be nothing clearing the cache other than the flushInternal.

However, for some reason the cache is getting cleared. Is there a way to log when this is happening or what is triggering it?

It *seems* this occurs with inserts / updates / deletes in Mapper "A".

Two questions:
  1. Can one mapper file clear the L2 cache for another mapper file?
  2. Is there a way to track the clearing of cache to understand what is triggering it more easily. I have briefly looked at the source code, but haven't done a deep dive yet.

Ryan Griffith

unread,
Jul 20, 2023, 6:37:12 PM7/20/23
to mybatis-user
I should add. 
  1. I'm using Spring and using the @Transaction annotation. 
  2. I did a mock test of querying my "B" mapper statement and confirming that I'm hitting the cache, then executing an update statement in mapper "A", then re-querying the statement in mapper "B", which is a cache miss and hits the DB again. This tells me that for some reason one mapper is clearing the other mapper's cache.

Iwao AVE!

unread,
Oct 4, 2023, 5:40:16 AM10/4/23
to mybati...@googlegroups.com
Hello Ryan,

Clearing cache in one mapper should not affect the other unless they share the namespace.
It's possible that I misunderstand your explanation, though.

Here is the test project that I used to verify.
Take a look and see if you could find the key differences.

Regards,
Iwao

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/3925fa23-7e69-4e67-ab5a-7365163c9855n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages