createDataCache - Prefetch Issue

May 27, 2011 at 1:42 PM

I am testing functionalities on datajs using eBay oData + datajs and i have great experience.

I have one hypothetical situation:

Web application where you are using URL address to direct listing the specific page of items from some category, for example:

When i get first request, i want to get page querystring value, and to make call to eBay oData service using datajs. 
After that I am using paging and navigating using local variables for pagenumber, datajs and caching for displaying appropriate data. 

It is working fine, but as i see, when i put prefechSize:20 for example, it makes asynchronious calls data service to get to get NEXT 20 items, every time i access the last cached page.

OData.defaultHttpClient.enableJsonpCallback = true;
var startPage = 0; var cache = datajs.createDataCache({ name: "categories",
pageSize: 10,
prefetchSize: 10, });

For example:



My question is: what about PREVIOUS, isn't it better to determine is there items before "prefetch" call and to make double call for caching (for next 20 and for previous 20).

Or maybe i should use cache.onprefetch event do handle this situation?


Vlatko Ivanovski

May 27, 2011 at 6:52 PM

Vlatko, you are right that "moving forward" isn't always the right thing.

We've implemented it for now by moving forward because that is overwhelmingly the most common case, but I think that ideally we would try to make sure that the following are always in the cache: first page, previous page, next page, last page. Those are the four most-likely places the user would go to after reading a page.

For now however we're keeping it simple, and it seems like in practice this does provide a pref boost in most scenarios, but we're always willing to learn more.