dojo.store.Cache
restStore = new dojo.store.JsonRest(...); memoryStore = new dojo.store.Memory(); store = new dojo.store.Cache(restStore, memoryStore); store.get(1) -> Returns the object with an id of 1 by making a GET request store.get(1) -> Returns the object, using the local memory cache store.put({id:2, name:"two"}) -> Stores the object in both master and cache store store
dojo.store.Observable
// create the initial Observable store store = dojo.store.Observable(new dojo.store.Memory({data: someData})); // query the store var results = store.query({rating:5}); // do something with the initial result set results.forEach(insertRow); // now listen for any changes var observeHandle = results.observe(function(object, removedFrom, insertedInto){ if(removedFrom > -1){ // existing object removed removeRow(removedFrom); } if(insertedInto > -1){ // new or updated object inserted insertRow(insertedInto, object); } }); // this will trigger an addition to the result set (the observe listener will be called) store.put({rating: 5, id: 3}); // this will *not* trigger a observe event, since the object does not match the query constraint (query was for rating = 5) store.put({rating: 3, id: 4}); // if this object was in the result set, it will trigger a observe event store.remove(2); // done observing, any further modifications will not trigger our listener observeHandle.cancel();
dojo.store.Memory
var someData = [ {id:1, name:"One"}, {id:2, name:"Two"} ]; store = new dojo.store.Memory({data: someData}); store.get(1) -> Returns the object with an id of 1 store.query({name:"One"}) -> // Returns query results from the array that match the given query store.query(function(object){ return object.id > 1; }) -> // Pass a function to do more complex querying store.put({id:3, name:"Three"}); // store the object with the given identity store.remove(3); // delete the object