Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dstore/Cache::put #154

Merged
merged 1 commit into from
May 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,20 @@ define([
});
},
put: function (object, directives) {
// first remove from the cache, so it is empty until we get a response from the master store
// first update the cache, we are going to assume the update is valid while we wait to
// hear from the master store
var cachingStore = this.cachingStore;
cachingStore.remove((directives && directives.id) || this.getIdentity(object));
return when(this.inherited(arguments), function (result) {
cachingStore.put(object, directives);
return when(this.inherited(arguments)).then(function (result) {
// now put result in cache
var cachedPutResult =
cachingStore.put(object && typeof result === 'object' ? result : object, directives);
// the result from the put should be dictated by the master store and be unaffected by the cachingStore,
// unless the master store doesn't implement put
return result || cachedPutResult;
}, function () {
// Assuming a rejection of a promise invalidates the local cache
cachingStore.remove((directives && directives.id) || this.getIdentity(object));
});
},
remove: function (id, directives) {
Expand Down