mrappleton/backbone-fetch-cache — pull request #15 by inf0rmer (2013-04-19 13:20:55+00:00)
Title: Automatically expire cached items that are considered stale.

Hey again!

While integrating this library into my app I noticed that QUOTA_EXCEEDED errors were not being caught, so I thought of implementing this feature:

- When trying to write to the cache, catch said errors and try to purge one item off the cache to make space.
- Items are purged according to a new function defined in ```Backbone.fetchCache```, ```priorityFn```. By default this sorts a cache array according to the highest ```expires``` value (so, the oldest items). The implementor can override this with a custom function though, as you can see in the specs.

I think this is a good starting point, although it still needs improvements. Right now it doesn't recursively try writing to the cache, it just tries to clear one item and then rewrite the cache with the contents of Backbone.fetchCache._cache.

What do you think of this feature? Is it worth it to incorporate into your main branch?

Thanks!