Khan/khan-exercises — pull request #8220 by majek (2011-12-09 13:31:28+00:00)
Title: Fix #8115 - localStorage LRU abstraction - quota problems

As discussed in #8115 - it's possible to exceed the quota on `window.localStorage`.

Proposed solution is to wrap all the sets/gets to exercises localStorage data in a simple LRU abstraction. By keeping ordered index we will know which items weren't used for a while and we'll be able to remove the oldest ones when the threshold is reached.

1) I arbitrarily set the threshold to 40 entries.

2) The code uses `underscore` library. I assume that it's loaded at the time when `handleSubmit`, `updateData` or `getData` will be called.

3) Actually, it may make sense to pull the LRU abstraction to another file. Suggestions welcome. (beware LRU is actually initiated quite early on, before other dependencies are loaded)

4) I've written few tests for the LRU abstraction code, see: 3795e409f93166f1713f9cd00b5a1c9e65d56ffe (not part of this pull request). The tests run successfully on recent Firefox, Chrome, Opera, Safari and IE8.

5) Beware, that sandcastle version of `khan-exercises` doesn't use localStorage at all - I'm not able to test if my pull request actually works (although, as mentioned before, the LRU abstraction was tested separately). Further verification may be required.