This project is read-only.

Dirty Cache (SOLVED)

Mar 21, 2013 at 7:09 PM
I've noticed that ndatabase seems to be caching items in memory and its pretty easy to make the cache go out of sync.
 //store model with name='Name'
 _testModel.Name ="Name";
Db.Store(_testModel);

//Check that it is stored correctly
Db.AsQueryable<TestModel>().Sinlge().Name.Should().Be("Name");

//Update the instance in memory without calling store
_testModel.Name = "New Name";

//Get the object from db again, should have the last stored name
Db.AsQueryable<TestModel>().Single().Child.Should().NotBeNull();
is there a way to disable this cache or force the db to bypass it?
Mar 22, 2013 at 9:03 AM
Hello,
nope, there is no possibility to disable cache (it is used to find where you are using update and where you are inserting new object).

The recommended work is to have UnitOfWork entities, everyone surrounded with using so you are committing and next time you are using fresh cache. In your case, that will solve the problem with long running cache.

Regards,
Jacek
Mar 22, 2013 at 7:51 PM
Whats the recommended way of creating a new unit of work?
Mar 24, 2013 at 9:57 AM
If you follow Unit of Work pattern, then you have a recommended way.

There is no special way for NDatabase, that's rather common way of creating access units for your domain, so every method describing your actions will contain using declaration to open and finally close the NDatabase.