Grid takes care of page caching on client so not needed in container?

I’ve been looking at a container implementation specifically for lazy loading data into a Grid.

I noticed that Grid uses
DefaultCacheStrategy
to cache rows in the client. The java docs state that it uses “multiples of the page size for determining the minimum and maximum number of items to keep in the cache”. I was just starting to implement a similar caching strategy on the server-side, but I now see that it may not be necessery as the client has its own cache which it will fill up with data ahead of scroll actions by the user anyway.

All I have to do is cache the result form getItemIds(from, numberOfItems) on the Container.Indexed interface, for subserquest calls to getItem.

Am I on the right track here?

I think a deep dive into containers and their runtime behavour would make an excellent topic for a webinar.

Yes, you can keep all the data in memory on the server side if the memory usage is acceptable to you. That’s indeed how Vaadin’s AbstractInMemoryContainer and its subclasses work - and Table also does lazy loading on the clientside independent on how its Container works, so Grid is nothing new in that regard.

Thanks for the reply. I’m not planning on holding
all
the data in memory, just the data requested by a single call to getItemIds(from, numberOfItems).

It’s based on the assumption that Grid makes the following calls as it populates its client side cache:

  1. Call getItemIds(from, numberOfItems)
  2. Call getItem(id) for each of the ids (loaded into client side cache)

This implies that I only need to store data from the item ids requested by grid in memory. When there is a subsequent call to getItemIds, I clear this cache out and reload it with data for the new ids.

This works for the most part, except that Grid also calls getIdByIndex to remove ValueChangeListeners for rows that have become inactive. This means that I have to maintain a cache of index to id mappings to service this request as Grid removes inactive rows from its cache. This is problematic, since I have no way of determining what grid’s caching strategy is so I have to make a guess.

Noticed the code has changed and the above quoted passage is not the case anymore.

Looks like this has been changed via:

http://dev.vaadin.com/ticket/16550

The ActiveRowHandler no longer makes calls to the container relating to rows that are inactive which means that the container doesn’t need to keep track of them any more.