Fork me on GitHub

The in-memory store

The in-memory store is offered as a fallback for browsers that do not support any of the other supported stores (e.g. WebSQL or Gears). In principal, it only keeps data in memory, which means that navigating away from the page (including a reload or tab close) will result in the loss of all data.

A way around this is using the persistence.saveToLocalStorage and persistence.loadFromLocalStorage functions that can save the entire database to the localStorage, which is persisted indefinitely (similar to WebSQL).

If you're going to use the in-memory store, you can configure it as follows:

persistence.store.memory.config(persistence);

Then, if desired, current data can be loaded from the localStorage using:

persistence.loadFromLocalStorage(function() {
  alert("All data loaded!");
});

And saved using:

persistence.saveToLocalStorage(function() {
  alert("All data saved!");
});

Drawbacks of the in-memory store:

  • Performance: All actions that are typically performed by a database (sorting, filtering), are now all performed in-memory using Javascript.
  • Limited database size: Loading and saving requires serialization of all data from and to JSON, which gets more expensive as your dataset grows. Most browsers have a maximum size of 5MB for localStorage.
  • Synchronous behavior: Although the API is asynchronous, all persistence actions will be performed synchronously on the main Javascript thread, which may make the browser less responsive.
stores/memory.txt · Last modified: 2011/02/02 09:56 by Zef Hemel