LiteDB as in-process caching

Created on 18 Aug 2016  路  8Comments  路  Source: mbdavid/LiteDB

Hi @mbdavid,
Can we use for in-process caching?. Can we use same instance across multiple threads for concurrent reads?.

Thanks,
Imran.

question

Most helpful comment

Hi @nerai, current version support this way: One process, two thread, each thread open/close datafile using using(...) statment. Do not share LiteDatabase instance across multiple threads.

In next major version will be "thread-safe". One process, ONE single LiteDatabase instance, MANY threads using same LiteDatabase instance (this way is much more simple to controls over current implementation and make much more sense in local/mobile/desktop apps).

All 8 comments

For now, no. Current version of litefb are not thread safe, so you must open/close LiteDatabase instance. LiteDB supports concurrent open instances.

I麓m working on dev branch to complete change this: single instance supporting multi thread and no concurrent instances open same file.

Hey @mbdavid,
As it is now, it is very practical for multiple processes to share one db file. Are you going to leave this option or not?

Hi @henon, that the idea. For now, LiteDB supports multi process access but no multi thread. Works fine but have a lot of problem with that: it's quite slow (open/close file all times), concurreny fails (corrupting datafile), no cache support....
Using a single instance database I will open once (in exclusive mode), no other instances can access (so, no corrupt datafile), use lock operations to multi thread support, support cached pages... it's will works more like a "server based dbms". And, if you don't wat use like this, can still using using statment and avoiding databased open.

But it's only in plans... I'm just writing my README.md to help me.

Hi @mbdavid, just to make sure I've understood you correctly: Let's say I've got one process with two threads. Both threads create a new, private instance of LiteDatabase for themselves. Is that a supported scenario?

Hi @nerai, current version support this way: One process, two thread, each thread open/close datafile using using(...) statment. Do not share LiteDatabase instance across multiple threads.

In next major version will be "thread-safe". One process, ONE single LiteDatabase instance, MANY threads using same LiteDatabase instance (this way is much more simple to controls over current implementation and make much more sense in local/mobile/desktop apps).

@mbdavid when would this version be available?

Hi @Workshop2, no plans yet. I need think about this before start coding. I organizing source code yet, to be more modular and be simple to mantain.

Hi guys, new v3-beta was released. So now, my recomendation is use single-instance of LiteDatabase across threads. I will update documnetation in few weeks

Was this page helpful?
0 / 5 - 0 ratings