Is there plan to have ember-data cache with a persistent in-browser store?

I have an application that requires records loaded from the API to be available from a cache on reload. I have tried a number of different ways to achieve this, but nothing has worked great so far. My attempts have been to use localforage to cache records, but expiring records is a trick, and I’m looking for something better. I am about ready to try out ember-orbit instead of ember-data.

What I’m asking is, are there any libraries that help ember-data cache with localStorage or IndexedDB? Is caching with local persistence on the roadmap for ember-data?

Does https://github.com/kurko/ember-localstorage-adapter look like what you’re looking for?

@ulisesrmzroche, kind of but not really. I have used that library in the past as well as ember-localforage-adapter. Those are fine if you plan on always accessing your data via localstorage. When I was using these localstorage adapters, I would specify for a particular model that the model uses LSAdapter instead of ActiveModelAdapter. What I am looking for is a way of using localstorage as a mirror of the in-memory cache that is store:main. This way if a page was refreshed, store:main would be hydrated from localstorage. I want to be able to access models via a REST API, but have the result cached locally in localstorage.

I just noticed this StackOverflow question from February 2013 that is another explaination of exactly what I’m looking for. As far as I can tell, ember-orbit is the only way to accomplish a localstorage cache. As far as I can tell, if you use ember-orbit, you must completely remove ember-data. I’d prefer to keep using ember-data and cache to localstorage.

1 Like

ember-sync tries to solve the use case of applications that need to work offline and sync their data with a server whenever they get access to the network. This is not exactly the same use case as “just” caching records to avoid repeating requests to the server, but some of the issues are similar.

2 Likes

I use ember-pouch for this on Myapp

The PouchDB(‘bloggr’) stores in indexedDB and the db.sync syncs with the backend. If you don’t have a backend it will work. You can remove the db.sync('http://localhost:5984/bloggr', {live: true}); line.

var db = new PouchDB('bloggr');
db.sync('http://localhost:5984/bloggr', {live: true});

export default EmberPouch.Adapter.extend({
  db: db
});

Source: GitHub - broerse/ember-cli-blog: Tom Dale's blog example updated for the Ember CLI

1 Like

@martin ember-sync looks very interesting. I may add that in. Since I posted this, I developed my own localStorage cache system. I need to refactor it a bit before I can make it available on github. Still though, ember-sync solves some problems I have not tried to solve, and could be very useful for my project.

@broerse I looked at ember-pouch. Seemed like a very cool idea. Since ember-pouch uses indexedDB, only the newest version of Android (4.4) can use indexedDB, which doesn’t work for my project.

PouchDB uses IndexedDB in Firefox/Chrome/Opera/IE, WebSQL in Safari and most mobile browsers, and LevelDB in Node.js. It is currently tested and fully supported in:

  • Firefox latest stable (v29)
  • Chrome latest stable (v34)
  • Desktop Safari latest stable (v7)
  • Internet Explorer v10+
  • Opera latest stable (v21)
  • Android 4.3+
  • iOS Safari latest stable (v7.1)
  • Node.js

PouchDB is experimental on Android 2.x and various mobile browsers and environments including Apache Cordova. It is known to work, but you may run into issues. They are working on these issues. My example ( Myapp ) works on my old Android phone (don’t know the version) without issues.

@broerse, that is great that it also supports WebSQL. I think the other thing that I remember being more of technical hangup for me was how to do selective sync for individual users. I wasn’t sure how CouchDB and PouchDB would be able to selectively synch content as well as enforce security to synchronize select data. I’m sure there’s a way, I just didn’t go through the effort to figure it out. I’m good with relational databases, MongoDB, and Redis, but I couldn’t grock CouchDB’s synchronization. I’m sure that learning how CouchDB replicates would be very a good thing to know. When I made a cursory attempt to figure out selective replication in Couch, I didn’t find any good resources. @broerse, if you happen to have any bookmarks on that subject, could you send them my way?

http://wiki.apache.org/couchdb/Replication#Filtered_Replication http://couchio.tumblr.com/post/468392274/whats-new-in-apache-couchdb-0-11-part-three-new

http://hood.ie/

@mrinterweb - Did you get to complete the caching project? if so, I love to see the github repository.

@mrinterweb I’m interested in seeing what you came up with too.

Maybe someone can explain it to me here? Ember-data offline data persistence, maybe ember-pouch is not useful? Maybe I need something else?