JakeHova
JakeHova

Reputation: 1365

BreezeJS offline/online management

Background: I'm getting ready to start a project that has a requirement for mobile first. I'm using AngularJS for the client side, SQL for the DB and .net WEBApi2 for communication. I have read about BreezeJS and would like to use it as my offline data management piece primarily because I'm using EF6 on the .NET side of things and I like the idea of Breeze being able to manage and create entities via the EF metadata.

While designing the application, I got stuck on the idea of how exactly to manage sudden network loss. It is my understanding that BreezeJS stores it's EntityManager in working memory as it is being used. If a user is working online and then the browser crashes or the computer shuts down and then the webapp is re-opened in an offline setting, does Breeze gracefully recover or is that a use case I need to handle?

Question: I guess my question is simply, is there a way that I can force BreezeJS to NOT use working memory but to work off localStorage instead? If not, should I exportEntities to local storage every change or is there a better way to handle this particular use case?

Upvotes: 3

Views: 337

Answers (1)

Jay Traband
Jay Traband

Reputation: 17052

Breeze cannot automatically work with localStorage, however you can create a timer that periodically stores the EntityManager state to localStorage. Not sure it's a great idea however.

You do need to distinguish between the case where the server is unavailable, in which case it makes perfect sense to store the EntityManager to localStorage so that you can persist any changes when the server comes back up. As opposed to worrying about the browser/client computer crashing, in this case, I think it's better to just not handle this case. The complexity and perf implications are pretty large and if you are really worried about this then just perform a save (to the server) after each change ( again not necessarily a recommended approach, but it is available).

Upvotes: 2

Related Questions