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

Cache.js deletes element while waiting: necessary? #117

Closed
mercmobily opened this issue Apr 25, 2015 · 2 comments
Closed

Cache.js deletes element while waiting: necessary? #117

mercmobily opened this issue Apr 25, 2015 · 2 comments

Comments

@mercmobily
Copy link

Hi,

Cache.js has the following lines:

 put: function (object, directives) {
        // first remove from the cache, so it is empty until we get a response from the master store
        var cachingStore = this.cachingStore;
        cachingStore.remove((directives && directives.id) || this.getIdentity(object));
        return when(this.inherited(arguments), function (result) {

That cachingStore.remove is giving me a lot of grief, because I am listening to update events:

 store.on( 'add,update,delete', function( event ){
            var first = store.memCache.data[ 0 ];

And the problem is that when the listener runs, the cache is effectively missing the element (and I need it to be there).

Why are we deleting that element? This is what used to happen with Dojo's store... but is it strictly necessary? Isn't it a borderline bug, to have an incomplete cache for cached stores? Is there any chance we could make that deletion optional? (it really throws a spanner in the works for me)

@makario
Copy link

makario commented May 1, 2015

I too experienced a lot of grief while listening to updates because of this; ended up having to remove that line.

I understand that the reason for deletion is that the put() implementation of the cachingStore is asynchronous and can potentially take a "long time", and you don't want the existing item to be fetched since it's technically obsolete.

But in my opinion, fetching an obsolete item is not much worse than a cache miss that could maybe possibly happen in a really really small window of time before the put() operation completes. It becomes even less of an issue since if you're listening for updates.

@kitsonk
Copy link
Contributor

kitsonk commented Sep 1, 2015

Personal opinion, I don't see why we go ahead and assume the "best" with .put() and update the cache and then re-update when master resolves or remove when master rejects. I will work up a patch.

@dylans dylans added this to the 1.2 milestone May 24, 2017
kitsonk added a commit that referenced this issue May 24, 2017
Previous behaviour was to remove the item while waiting for return
from the master store.  Now Cache will presume the update will
complete and only remove the item if the master store rejects the
`put`.

Fixes #117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants