

BankersBox - a Redis-like API for localStorage - jazzychad
http://www.twilio.com/engineering/2012/03/05/open-sourcing-bankersbox

======
unoti
I was using (abusing?) localStorage for a game I'm working on. I was using it
to store entries for every word in the English dictionary, which is around
85,000 entries. I needed two entries per word actually, because I needed it
indexed two ways. It worked; I tested it on Chrome Linux, Mac Safari, a first
generation ipad, and on Android. However, it was slow to load, and started
erroring out sometimes in Chrome Linux, saying quota exceeded or something
along those lines. Basically I ended up deciding that localStorage wasn't
right for me for large amounts of data, and redid it another way.

These look like awesome and useful abstractions for a lot of things, I may use
it for saving and loading games, for example. But I recommend caution if
you're thinking about using localStorage to store a lot of entries.

~~~
pamelafox
The quota for localStorage varies from 2MB to well, very high, depending on
the browser. The average is around 5MB. There's a page here that shows results
for various browsers: <http://dev-test.nemikor.com/web-storage/support-test/>

It's not advisable to use it for a lot of data, especially if you actually
need that data to stay around - it's better in situations where it's okay if
the data goes away. You also need to be ready to handle over quota errors -
e.g. in my lscache library, we kick out old data when that happens. I talked
about that in a localStorage talk recently (<http://client-side-
storage.appspot.com/> \- click "show notes").

You might want to use the Lawnchair library, as that can be used with both
localStorage and IndexedDB, which can theoretically handle a lot more data
with better performance.

~~~
unoti
Thanks for sharing this! lscache is super cool. I also just watched and
thoroughly enjoyed your Google IO talk on shyness work-arounds
([http://www.youtube.com/watch?v=52Ml_zax4A0&t=24m9s](http://www.youtube.com/watch?v=52Ml_zax4A0&t=24m9s)).
Great stuff all around.

------
nbclark
Some nice abstractions. I would like more information on how they are using it
within Twilio, though.

~~~
jazzychad
Thanks! We are using it for internal web apps right now used for testing
existing and new products. That's about all I can say for now.

~~~
newman314
How well is it working in light of the article from Mozilla?
[http://hacks.mozilla.org/2012/03/there-is-no-simple-
solution...](http://hacks.mozilla.org/2012/03/there-is-no-simple-solution-for-
local-storage/)

~~~
Joeri
I'm using localstorage to remember settings that used to be stored in cookies.
These are things like the collapsed state of a panel, the dimensions of a
popup window, and the most recently used values of a location picker. It works
really well for that.

I think people run into problems when they store megabytes instead of
kilobytes. Localstorage is essentially cookie storage without the networking
dependency. Treat it like that and it works well.

------
bjornsteffanson
This is really cool. The entry barrier to building HTML5 mobile apps gets
lower every day, thanks in part to developers like those at Twilio who open-
source their hard work for the benefit of the community. Thanks for sharing.

------
methoddk
I had been thinking about something like this for an app I'm working on, this
looks great! Thanks for the awesomesauce.

------
dinedal
I wonder what the browser compatibility is for this? (anything with
localStorage ?)

~~~
pamelafox
The localStorage compatibility table is here:
<http://caniuse.com/#feat=namevalue-storage>

Many localStorage libraries fallback to older techniques (window.name,
userData, etc). It looks like BankersBox has an adaptor interface, so if you
wanted support in the older browsers, you could write an adaptor (check out
Lawnchair/store.js to see how to use those older APIs).

