Are there greenDAO thread safety best practices?

后端 未结 2 1433
闹比i
闹比i 2021-02-12 17:52

I\'m having a go with greenDAO and so far it\'s going pretty well. One thing that doesn\'t seem to be covered by the docs or website (or anywhere :( ) is how it handles thread

2条回答
  •  一整个雨季
    2021-02-12 18:14

    By default GreenDAO caches and returns cached entity instances to improve performance. To prevent this behaviour, you need to call:

    daoSession.clear()

    to clear all cached instances. Alternatively you can call:

    objectDao.detachAll()

    to clear cached instances only for the specific DAO object.

    You will need to call these methods every time you want to clear the cached instances, so if you want to disable all caching, I recommend calling them in your Session or DAO accessor methods.

    • Documentation: http://greenrobot.org/greendao/documentation/sessions/#Clear_the_identity_scope
    • Discussion: https://github.com/greenrobot/greenDAO/issues/776

提交回复
热议问题