mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.62k stars 1.25k forks source link

Is it possible to save change on disk without disposing LiteDatabase? #132

Closed vasiliy-vdovichenko closed 8 years ago

vasiliy-vdovichenko commented 8 years ago

I am trying to have one instance of LiteDatabase for entire application (multiple thread may access the instance simultaneously) and just save changes to disk when some entities are modified. Is such scenario possible in v2 ? Or it would be better to create LiteDatabase for each time when access to DB is needed?

mbdavid commented 8 years ago

Use a new instance per request. Open database is cheap (read only 1 page) and process safe.

LennardF1989 commented 4 years ago

@mbdavid Is making new connections everytime you need to do something with LiteDB still the recommended approach for v4/v5 too? Right now (in IIS / .NET Core), we use a singleton service and re-use that all over the place with no particular issue, aside from the occasional drop of info between recycles.

ItSkary commented 3 years ago

Use a new instance per request. Open database is cheap (read only 1 page) and process safe.

Isn't that raccomandation directly in contrast with that one? https://github.com/mbdavid/LiteDB/issues/394

I know both the posts are old, but i am confused, shuld i reuse connection or not? I am in multi thread environment, not reusing connection, sometimes give you a file lock exception.

Should i switch to shared in the connection string? Or shared mean slow (as stated in the documentation).

Sorry for all these questions, but searching thorught different post i get different solution (sometimes opposite), i suppose becasue things change a bit over time.

LennardF1989 commented 3 years ago

@mbdavid Could you answer my question above? Is making new connections everytime you need to do something with LiteDB still the recommended approach for v4/v5 too? Right now (in IIS / .NET Core), we use a singleton service and re-use that all over the place with no particular issue, aside from the occasional drop of info between recycles.

We are however experiencing some deadlocks from time to time (see #1863), and was wondering if this could be because of the singleton? But we also don't want to get rid of the singleton uninformed.

haiduong87 commented 3 years ago

@LennardF1989 Can you try this https://github.com/mbdavid/LiteDB/issues/1546#issuecomment-828674465 I tried with the provided test case and it's okay.

Iamknownasfesal commented 2 years ago

Any updates on this? @mbdavid