This maybe a boring commonplace question, but I have not found an answer by stackoverflow:(
-
PerpetualCache is a part of BaseExecutor, you can't disable it, memory will be high when you have many sessions and many large results. I have to change scope to statement or set flushCache to true, and PerpetualCache will put and remove results once by once.
-
If I enable 2nd cache by add
<cache/>
, 1st cache will be useless at all, but mybatis still adds results into it. Besides, Mybatis will use SynchronizedCache who adds synchronized for getObject/putObject/removeObject because PerpetualCache uses HashMap, it's not as efficient as ConcurrentHashMap. So when enabling 2nd cache, use a ConcurrentHashMap based cache other than PerpetualCache, remove SynchronizedCache, is it better?
Comment From: harawata
On Stack Overflow, you can post a new question if you cannot find the answer you are looking for. :)
- This may be a duplicate of #1278 #1633
Note that the 1st level cache (a.k.a. local cache) is used in mapping process and is not useless even when the 2nd level cache is enabled. - Migration to
ConcurrentHashMap
was discussed in #1544 and I am OK with your idea, basically. If you send us a PR, we will review it.
I'll close this issue as it contains multiple requests (which is not good when using tracker).