8

I'm using greendao for a android project and wanted to know how to properly delete and object from the db and from the session cache. Currently I do the following to delete from the db:

ChatDao chatDao = daoSession.getChatDao();
chatDao.queryBuilder().buildDelete().executeDeleteWithoutDetachingEntities();

However as the method name and documentation state this may leave stale objects in the session cache, how can I remove the objects from there too?

marchinram
  • 5,698
  • 5
  • 47
  • 59

2 Answers2

9

In order to clear cached objects in your DaoSession use this call:

DaoSession.clear();

It will clear all objects in your session identity scope.

Anatoliy
  • 500
  • 3
  • 17
5

As Anatoliy described, you can use DaoSession.clear(). However, it will clear all all objects from the session. If you want to avoid that, you have to execute a regular query and delete the result entities (for example with deleteInTx).

Markus Junginger
  • 6,950
  • 31
  • 52
  • 6
    Can I not delete the cached objects of a specific entity instead of ALL cached objects ? For example doing something like this : **ChatDao.clear ()** ? – Leeeeeeelo Feb 14 '13 at 09:24