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

Dev 0.4: Caching a dgrid implies that stale cache prevents reload() from newly added elements #950

Closed
mercmobily opened this issue Jun 5, 2014 · 2 comments

Comments

@mercmobily
Copy link

Hi there,

I am using a dgrid to access a cached Rest store (observable is not part of the equation).
In _StoreMixin, a new collection is created, and stored in _renderedCollection:

https://github.com/SitePen/dgrid/blob/dev-0.4/_StoreMixin.js#L116-L128

         if(collection){
            var renderedCollection = this.collection = collection;
            if(this.sort && this.sort.length > 0){
                renderedCollection = collection.sort(this.sort);
            }

            if(renderedCollection.track){
                renderedCollection = renderedCollection.track();
                this._rows = [];

                this._observerHandle = this._observeCollection(renderedCollection, this.contentNode, this._rows);
            }

            this._renderedCollection = renderedCollection;
            this.refresh();
        }

However, this has implications when refresh()ing the grid.

If you put() a value into the original collection passed to the dgrid, the collection's cache is updated with the new item (obviously). This is all fine. However, if you then issue a refresh() to the grid, the "main" collection is not actually used -- instead, this._renderedCollection is used. At this point, this._renderedCollection has its queries cached. So, rerunning the query will use this._renderedCollection's cache, which will result in the result being returned -- without the newly added value.

After modifying the grid, when I want to refresh its data, I am doing this:

grid._renderedCollection._collectionCache = {}
grid.refresh( { keepScrollPosition: true } );

This ensures that query caches are neutralised for the _renderedCollection. But, it feels hacky.

Please note that you can say "Well, simply use canCacheQuery to prevent caching", but that would not be a solution: there would be no use case left for querying to happen at all in a dgrid! (Unless you are happy for partial results to be displayed all the time)

I hope this made sense.

@mercmobily mercmobily changed the title Caching a dgrid implies that stale cache prevents reload() from newly added elements Dev 0.4: Caching a dgrid implies that stale cache prevents reload() from newly added elements Jun 5, 2014
@kriszyp
Copy link
Contributor

kriszyp commented Jun 24, 2014

I believe this issue should also be corrected by the latest commits in dstore.

@kfranqueiro
Copy link
Contributor

Yes, that should resolve it, and dgrid's dev-0.4 branch is now updated to work with the updated dstore APIs.

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

No branches or pull requests

3 participants