1

I intend to create a cell table that show info about contacts from the DB. the table i'm about to display has alot of rows.

Currently I managed to display the data with ease. my only problem is, when i change a page in my pager. gwt sends a request for the data again and again, even though i already requested these pages before!

how can i make the client side caching ?

p.s here is a piece of code of the onRangeChanged:

AsyncDataProvider<Contact> provider = new AsyncDataProvider<Contact>() {
  @Override
  protected void onRangeChanged(HasData<Contact> display) {
    int start = display.getVisibleRange().getStart();
    int end = start + display.getVisibleRange().getLength();
    end = end >= DBHelper.size() ? DBHelper.size() : end;
    List<Contact> sub = DBHelper.get(start, end);
    updateRowData(start, sub);        
  }
};

EDIT:

Churro suggested that i will create a helper class (like DBHelper) that will cache some of the results and thats how i will skip a db access. Thats not what I intended, i indended to have a cache on the client side, the helper class still not gonna save me a client -> server call.

Urbanleg
  • 6,252
  • 16
  • 76
  • 139

2 Answers2

2

You should implement a class to help with the caching on the client. It will act as a layer between your service interface (DBHelper) and your CellTable. It will manage RPC requests, and only make RPC calls when data needs to be refreshed. Otherwise, it will returned the cached data, from some cache structure like a Map.

After it is implemented, your AsyncDataProvider will call CacheImpl.get(start, end); instead of DBHelper.get(start, end).

Churro
  • 4,166
  • 3
  • 25
  • 26
  • @Urbanleg If you just want to get the data once, then page through the retrieved data, you must use the `ListDataProvider` class instead of `AsyncDataProvider`. You can still make an RPC call, then send the results to the `ListDataProvider`, which will handle paging and sorting synchronously. – Churro Oct 08 '13 at 16:09
1

To help also with memory, I use a EntityWindow, what this does is it will keep two ranges previous and fetch two ranges prior. This way you can limit the amount of objects that are cached in memory and fetch the next two in the background in order to make next page even faster. On load you can fetch the data needed to render the view and in the background go and fetch 2x or 3x display.getVisibleRange().getLength() entities so that the next button loads immediately. When the user clicks next you can fetch the future elements and delete the previous elements.

Chris Hinshaw
  • 6,967
  • 2
  • 39
  • 65