MyBatis - Disable cache
Asked Answered
H

0

6

I need to disable the cache of MyBatis because I'm altering my database in other ways and want that MyBatis has always the latest version of my data ready. I tried numerous ways to disable it:

  • Calling SqlSession.clearCache() before every query
  • Adding <setting name="cacheEnabled" value="false" /> to mybatis-config.xml
  • Adding <setting name="localCacheScope" value="STATEMENT" /> to mybatis-config.xml
  • Adding @Options(flushCache = Options.FlushCachePolicy.TRUE, useCache = false) to every statement

Nothing works and I always get old data on queries.

Honebein answered 29/7, 2020 at 14:12 Comment(4)
Never had that problem. Are you sure the data was committed by the other thread?Smorgasbord
@TheImpaler Yes, I am sure. And when I restart my MyBatis implementation it just finds the new records.Honebein
I use MyBatis regularly and I've never faced this problem. I think caching is disabled by default, but I may be wrong. Is there any way I could reproduce the case, so I can debug it? It worries me, since I use it extensively.Smorgasbord
This might help you linkTraveled

© 2022 - 2024 — McMap. All rights reserved.