javascript - HTML5 Local Storage stringify's and stores EACH object reference -
with following json:
var myobj = {name: 'my obj', does: 'nothing'}; var myobjarr = [myobj, myobj, myobj];
when storing myobjarr local storage, myobj json wrtten 3 times, taking 3 times storage space, i.e:
"[{"name":"my obj","does":"nothing"},{"name":"my obj","does":"nothing"},{"name":"my obj","does":"nothing"}]"
obviously going present scalability issues. can recommend optimal solution? far i've had resort using id's, la relational databases.
var objects = {0: {name: 'my obj', does: 'nothing'}}; var myobjarr = [{obj: 0}, {obj: 0}, {obj: 0}];
update - question how represent hierarchy in local storage when data stored key/value strings. resorting relational database concepts seems old-school.
a more appropriate technology indexeddb used object store, isn't supported many browsers yet.
edit: you'll want browse through documentation of structured clone algorithm used when copying object indexeddb - looks references maintained per record, adding multiple records not result in each record referencing objects shared in javascript memory space.
Comments
Post a Comment