lucian1900/Backbone.dualStorage — Issue #8: Shorter localStorage Keys
Author: kurtmilam
Created: 2012-01-28 14:26:28+00:00
State: open

HTML5 storage is limited, and having to store a long `guid` for every object (or even a somewhat long `service + endpoint` for every object) will take up precious space. I think it would be enough to create one `guid` per browser/client. Let's say we call this `guid` 'localDbId'. Now, create one localStorage item per `Collection.url`. Then just use an incrementing number for the model keys:

1. Locally, each model would have an int key, value = the model
2. Each Collection would have a url key, value = delimited list of associated model IDs
3. Each database would have a single `localDbId` key containing a guid

On the local client, the incrementing number is enough to identify each store uniquely. When you think about syncing multiple devices to a central, remote store, you'd simply add each device's single `localDbId` to the incrementing number:
`url + '/' localDbId + '-' + n++`

Now you have a very cheap local unique identifier without losing your global identifier. This would be handy for developers who want to delegate id-creation to the client app, and would also allow tracking of which models were created by whom (more interesting for enterprise apps, maybe).