createDataCache - Prefetch Issue

May 27, 2011 at 1:42 PM
Hi,

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:

http://myapplication.com/20085/Items?page=4

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.

var EBAY_CATEGORIES = "http://ebayodata.cloudapp.net/Categories";
OData.defaultHttpClient.enableJsonpCallback = true;
var startPage = 0; var cache = datajs.createDataCache({ name: "categories",
source: EBAY_CATEGORIES,
pageSize: 10,
prefetchSize: 10, });

For example:

‎‎http://ebayodata.cloudapp.net/Categories?$skip=40&$top=20&$callback=handleJSONP_0&$format=json
‎‎http://ebayodata.cloudapp.net/Categories?$skip=60&$top=20&$callback=handleJSONP_1&$format=json
‎‎http://ebayodata.cloudapp.net/Categories?$skip=80&$top=20&$callback=handleJSONP_2&$format=json 

 

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?

Regards

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.

Thanks!

Marcelo