Opened 8 years ago

Closed 8 years ago

#14023 closed defect (invalid)

dojo.store.cache has different return values on get()

Reported by: Hounddog Owned by: Kris Zyp
Priority: high Milestone: tbd
Component: Data Version: 1.6.1
Keywords: Cc:
Blocked By: Blocking:

Description

While doing a get to the dojo.store.cache for an object that is not loaded yet, the cache store uses the dojo.store.JsonRest? to query the server and returns a deferred. If the Object was already loaded the cache takes it from the dojo.store.Memory and returns the item object.

The simplest solution would probably be to create a deferred for both so that you can just use the result in the callback.

var memory = new dojo.store.Memory({});
var rest = new dojo.store.JsonRest({
               target: '/xyz'
           });
var cache =  new dojo.store.Cache(
                rest, 
                memory
              );

cache.get(2);// First call will return a deferred item
cache.get(2);// Second call will deliver an object

Change History (1)

comment:1 Changed 8 years ago by ben hockey

Resolution: invalid
Status: newclosed

this is why dojo.when exists. see http://dojotoolkit.org/reference-guide/dojo/when.html#usage

dojo.when(cache.get(2), function (item) {
  // item is item with id of 2 every time
});
Note: See TracTickets for help on using tickets.