How to get the record count when using DataCache

Aug 27, 2011 at 12:59 AM


Following on from this thread :

Does the DataCache provide a means to include the total record count inline or do we need to query the total first?

e.g. can we do something like:

var options = { name: "cache", source: "$inlinecount=allpages", pageSize: cachePageSize, prefetchSize: itemsToPrefetch, cacheSize: cacheSize };
OData.defaultHttpClient.enableJsonpCallback = true;

var cache = datajs.createDataCache(options);

cache.readRange(firstIndex, itemsDisplayed).then(function (results) {
       var total = results.__count

I'm presuming not but just thought I check


Aug 29, 2011 at 12:30 AM

The cache will not return the count inline, but you can use the count method to get the value.

var cache = ...
cache.count().then(function(total) { alert("There are " + total + " items."); });

Hope this helps,


Sep 2, 2011 at 1:41 AM

Excellent thanks

Sep 11, 2011 at 9:52 PM

I was unable to use the .count method() because I was using JSONP on a remote server (Netflix) and it returned a 415 message.

I ended up doing a read for just a single item and including the inlinecount param before I accessed my cache.

That worked fine however it would be great if datajs hid this type of thing away and managed it for you i.e. use an alternate means itself if the standard method failed.