{"id":148,"date":"2011-12-29T23:17:25","date_gmt":"2011-12-29T22:17:25","guid":{"rendered":"http:\/\/www.speich.net\/articles\/?p=148"},"modified":"2011-12-29T23:17:25","modified_gmt":"2011-12-29T22:17:25","slug":"rest-with-dojo-and-php-notes-on-using-dgrid-with-a-caching-store","status":"publish","type":"post","link":"https:\/\/www.speich.net\/articles\/en\/2011\/12\/29\/rest-with-dojo-and-php-notes-on-using-dgrid-with-a-caching-store\/","title":{"rendered":"REST with dojo and PHP: Notes on using dgrid with a caching store"},"content":{"rendered":"<p>I would like to share some (personal) pitfalls I came across when creating the demo <a title=\"REST with dojo and PHP\" href=\"http:\/\/www.speich.net\/articles\/demos\/jsonrest\/dojo-demo-dgrid.php\">REST with dojo and PHP: Demo of a dgrid observing changes to the JsonRest store<\/a>:<\/p>\n<ul class=\"main\">\n<li>dojo\/store\/Observable only works correctly when the object has an id. Unfortunately, dojo\/store\/Memory.add(object) does not add the id to the object when creating it (as of 1.7.1) .\u00a0 See bugs <a title=\"dojo\/store\/Memory bug\" href=\"http:\/\/bugs.dojotoolkit.org\/ticket\/12835\">#12835<\/a> and <a title=\"dojo\/store\/Memory bug\" href=\"http:\/\/bugs.dojotoolkit.org\/ticket\/14281\">#14281<\/a>. For a fix see changeset <a title=\"Changeset fixing bug #12835 and #14281\" href=\"http:\/\/bugs.dojotoolkit.org\/changeset\/27072\/dojo\">#27072<\/a><\/li>\n<li>Observable does only work correctly with a store, that provides a queryEngine. dojo\/store\/JsonRest does not have a queryEngine by default, so you will have to provide your own. If you are using a cache, observe the dojo\/store\/Memory directly. <strong>Upate 29.06.2012:<\/strong> For a fix see changeset\u00a0<a title=\"changeset 29069\" href=\"http:\/\/bugs.dojotoolkit.org\/changeset\/29069\/dojo\">#29069<\/a>.<\/li>\n<li>As stated in the docs, but easily missed: dojo\/store\/Cache automatically adds all returned objects from get() and query() calls to the cache, but only get() uses the cache, whereas query() directly uses the master store. If you want the query to come from the cache, directly call query() on the caching store, e.g. dojo\/store\/Memory.<\/li>\n<li>In the demo, the PHP script responds to the GET 2 by returning a Json object with id 2 and to a GET 2\/ by returning an array of objects with parent id 2. If you want to query the Memory store for 2&#8217;s children, you have to provide an object as an argument, e.g. storeMemory.query({parId: 2}), whereas the JsonRest store expects a string e.g. storeJsonRest.query(&#8216;2\/&#8217;);<\/li>\n<li>JsonRest store&#8217;s methods do not return the same types as Memory store, which can be confusing&#8230;<br \/>\nstoreMemory.add(newObject) returns the id<br \/>\nstoreJsonRest.add(newObject) returns the response from the server (or rather a Deferred providing it)<br \/>\n&#8230;, but makes sense, because it can save an extra round trip to the server.<\/li>\n<\/ul>\n<p>Also see <a href=\"http:\/\/dojotoolkit.org\/reference-guide\/1.8\/dojo\/store\/Observable.html#id2\">dojo\/store\/Observable<\/a> and <a href=\"http:\/\/dojotoolkit.org\/reference-guide\/1.8\/dojo\/store\/Cache.html#id2\">dojo\/store\/Cache<\/a> more info.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I would like to share some (personal) pitfalls I came across when creating the demo REST with dojo and PHP: Demo of a dgrid observing changes to the JsonRest store: dojo\/store\/Observable only works correctly when the object has an id. Unfortunately, dojo\/store\/Memory.add(object) does not add the id to the object when creating it (as of &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.speich.net\/articles\/en\/2011\/12\/29\/rest-with-dojo-and-php-notes-on-using-dgrid-with-a-caching-store\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;REST with dojo and PHP: Notes on using dgrid with a caching store&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,6],"tags":[26,77,83],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-javascript","category-php","tag-dojo","tag-rest","tag-store","entry"],"_links":{"self":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":0,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.speich.net\/articles\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}