KarolDepka
KarolDepka

Reputation: 8628

Does Meteor-JS support offline storage/cache?

Does Meteor-JS support offline storage/cache?

From what I'm reading: https://guide.meteor.com/collections.html :

Instead, on the client, a collection is a client side cache of the database. This is achieved thanks to the Minimongo library—an in-memory, all JS, implementation of the MongoDB API.

The in-memory part seems to negate working offline. Am I wrong?

EDIT: By "offline" I mean as many as possible of those qualities:

EDIT2: I guess the proper term would be offline-first

Upvotes: 2

Views: 1608

Answers (2)

ghybs
ghybs

Reputation: 53205

You are right about having concerns about the "in-memory" part of Minimongo. But on an offline device this is not as bad as it can look like: as long as the app is kept in memory (i.e. sitting in a tab if opened through a browser, or not forcedly closed if opened as a Cordova packaged app), your Minimongo lives and retains your data.

However, should the browser tab be closed, or the Cordova app brought out of device memory (i.e. user forces it to close through the task switcher / apps manager, or Android is getting short of RAM and looks for unused apps to close. This also means that just going back to home screen keeps your app in memory), then your Minimongo (and its data) goes away.

But there are packages that can take care of that use case as well. See How can Meteor apps work offline?

Upvotes: 1

Ankit
Ankit

Reputation: 1128

This feature doesn't come out of the box. Even if you make changes to the client, they will be reflected in the client but once the connection to the server is established, the server data will I override the changes.

You will have to manually push the data. One way of doing this is using local storage of the browser. You can save the data in local storage and push it in the server once connection is established to make the changes 'permanent'.

As pointed out in comments: Meteor will try to keep calling the method, till the connection is re-established is using Meteor.call, but once the tab is closed the data in the client will be lost. So, ensure the data survives closing of tab, store it in local storage.

Upvotes: 1

Related Questions