On 4/26/2013 2:50 PM, Gavin Sharp wrote:
On Fri, Apr 26, 2013 at 11:36 AM, Andreas Gal <g...@mozilla.com> wrote:
Preferences are as the name implies intended for preferences. There is no sane 
use case for storing data in preferences. I would give any patch I come across 
doing that an automatic sr- for poor taste and general insanity.
As Greg suggests, that ship has kind of already sailed. In practice
preferences often ends up being the "best" choice for storing some
small amounts of data. Which is a sad state of affairs, to be sure -
so I'm glad we have this thread to explore alternatives.
The key problem with expanding this is that the pref API is designed to be synchronous because it controls a bunch of behavior early in startup. Our implementation is therefore to read all the prefs in (synchronously) and operate on them in-memory. That strategy only continues to work as long as the set of data in prefs is tightly constrained.

I really hope the outcome of this discussion is that we end up storing everything that isn't a true preference in some other datastore, and that is an async-by-default datastore ;-)
I have little experience actually trying to use indexedDB, so grain of salt etc., but my impression is that it's somewhat overkill for use cases currently addressed by preferences or custom JSON (e.g. a simple key-value store).
With a pretty simple JSM wrapper, indexeddb could be a very good solution for saving JSON or JSON-like things (you don't even need JSON, because indexeddb does structured cloning). It can of course be used for more complex things as well, but if we want a durable key-value store, it could be as simple as:

ChromeData.get('key', function(value) {
  // null if unset
});

ChromeData.set('key', value [, function()]); // asynchronous

Or maybe there's a better syntax using promises, but in any case it could probably be this simple.

Does anyone use indexeddb in chrome right now?

--BDS
_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to