1

Referencing the topic how to clear mybatis cache manually by code I stumbled over a issue with TransactionalCache which is the only MyBatis cache type which gets NOT cleared by calling clear() on every cache provided by sqlSessionFactory.getConfiguration().getCaches

In particular the member variables of org.apache.ibatis.cache.decorators.TransactionalCache

  private Map<Object, Object> entriesToAddOnCommit;
  private Set<Object> entriesMissedInCache;

are holding keys and values which should be chached on commit and which are not cached yet. So far so good. In my optinion both should be cleared on cache.clear(), but the responsible clear method gets never invoked

 @Override
  public void clear() {
    clearOnCommit = true;
    entriesToAddOnCommit.clear();
  }

Is this a bug or are there any explanation or suggestion how to flush TransactionalCache?

Community
  • 1
  • 1
Mahatma_Fatal_Error
  • 720
  • 1
  • 10
  • 26
  • BTW, clear meothods of every other dacorated cache like SerializedCache or LruCache gets invoked – Mahatma_Fatal_Error Mar 10 '16 at 17:51
  • Erm, is it really a good idea to be able to clear a Cache manually that seems to be wired heavily into the whole transaction system? To me it seems that the Cache is intended to react only to commit and flush events (via the TransactionalCacheManager). – Florian Schaetz Mar 11 '16 at 06:41
  • @FlorianSchaetz unfortunately it is necessary since there are writing sql statements apart of mybatis (but within the same transaction/connection) which should flush the cache as well when they are invoked. Imho even the TransactionalCacheManager should clear its cache, otherwise entriesToAddOnCommit holds values which gets written to cache on commit which are not valid anymore. FYI my local cache scope is set to STATEMENT and not SESSION. – Mahatma_Fatal_Error Mar 11 '16 at 09:33

0 Answers0