source: [view]
options = options || {};
return dojo.delegate(masterStore, {
query: function(query, directives){
var results = masterStore.query(query, directives);
results.forEach(function(object){
if(!options.isLoaded || options.isLoaded(object)){
cachingStore.put(object);
}
});
return results;
},
// look for a queryEngine in either store
queryEngine: masterStore.queryEngine || cachingStore.queryEngine,
get: function(id, directives){
return dojo.when(cachingStore.get(id), function(result){
return result || dojo.when(masterStore.get(id, directives), function(result){
if(result){
cachingStore.put(result, {id: id});
}
return result;
});
});
},
add: function(object, directives){
return dojo.when(masterStore.add(object, directives), function(result){
// now put result in cache
return cachingStore.add(typeof result == "object" ? result : object, directives);
});
},
put: function(object, directives){
// first remove from the cache, so it is empty until we get a response from the master store
cachingStore.remove((directives && directives.id) || this.getIdentity(object));
return dojo.when(masterStore.put(object, directives), function(result){
// now put result in cache
return cachingStore.put(typeof result == "object" ? result : object, directives);
});
},
remove: function(id, directives){
return dojo.when(masterStore.remove(id, directives), function(result){
return cachingStore.remove(id, directives);
});
},
evict: function(id){
return cachingStore.remove(id);
}
});