Start a new topic

Offline - maxAge - potential bug

Angular 1.1.7

offline: true, maxAge: 30, Multi-entity query

On Chrome (that uses IndexedDB) if you

a) Do query (so cache set)

b) Change data on Kinvey (via console)

c) Wait a few seconds (i.e. so local data is now over 30 seconds old)

d) You see the new data set in b, when requested from via JS library

On Safari (and on IOS web view), uses a different type of local storage I think

a) Do query (so cache set)

b) Change data on Kinvey (via console)

c) Wait a few seconds (i.e. so local data is now over 30 seconds old)

d) You see the original data, not the new data set in b, when requested via JS library

I would expect Chrome and Safari to work the same. And the Chrome outcome is how I would expect it

Can you confirm that maxAge works (in multi-entity queries) on all styles of local storage you work with?


(maxAge is awesome FYI)

In Safari, WebSQL is used as underlying storage. Do you know the exact Safari version number? I ran the use-case you described, and I get the expected fresh result.
Hello Mark

Just tested on 7.0.3 (9537.75.14) (on laptop)

IOS Webview has the same issue (whatever version is on IOS 7.1)

Just tested by renaming the collection (so its 100% fresh, locally) and still the same problem. This is the code I am using

var query = new $kinvey.Query();

query.equalTo('code', code);


var promise = $kinvey.DataStore.find('collection-name', query, {

offline: true,

maxAge: 30,

success: function (response) {




Thanks for looking into it!

OK I think I fixed it

Angular library

maxAge status code

var itemMaxAge = (maxAge || item._kmd.maxAge || 0) * 1000;

rather than

var itemMaxAge = (maxAge || item._kmd.maxAge) * 1000;

I think that occasionally both maxAge and item._kmd.maxAge were NaN and this caused knock on issues. My suggestion above falls back to zero in this situation. (Probably a deeper analysis required as to why both are NaN sometimes!)
Although I have a suggested solution above please do consider testing and integrating into the main angular library so this fix is available for others.....
I was trying to wrap my head around this, but am so far unable to reproduce. I can certainly add the fix you proposed if you feel AngularJS now works correctly in Safari and iOS Webview.
DELETED as was wrong
DELETED as was wrong
OK going back to the cause of the NaN :)

Current code in Angular library (on the read)

var status = maxAge.status(response);

Function itself in current Angular library

status: function(data, maxAge)

Proposed code

var status = maxAge.status(response, options.maxAge);

i.e. maxAge from the query is not actually being sent to the function (causing a NaN in one of the calcs, if the value is NOT on the data itself)

This removes the NaN on the read and seems to fix it! (ha, yeah, think I said that before)

(Maybe you couldn't recreate this scenario as the data you were testing with had maxAge set on the data itself, in which case you wouldn't see the NaN as that would have been pulled into the function on the data)

If you like this fix and it passes your tests, probably a good one to put in.

This seems like a bug to me indeed, tests were flaky on this point. This will be incorporated in the next release.
This has now been updated! See
Login or Signup to post a comment