Skip to content

Commit

Permalink
Stop doubling the min-refresh rate if the server doesn't specify one
Browse files Browse the repository at this point in the history
Now that we only run when live cached elements are on the page, there's no real benefit to this
  • Loading branch information
John P. Bloch committed May 7, 2014
1 parent 0ab8398 commit b0c813d
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions live-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
values = [],
callbacks = [],
timeStamp = 1,
minRefresh = 60,
errs = 0,
runCache = null;

function getRefreshRate(rate) {
rate = parseInt(rate, 10);
return Math.max(rate, 60);
}

this.auto_updates = LC.auto_updates;

// schedule first check
Expand Down Expand Up @@ -41,12 +45,12 @@
url : ajaxurl + '/live_cache_check/' + timeStamp + '/',
success : function (data, s, resp) {
var time = resp.getResponseHeader('Date').split(" ")[4];
// check our special variable refresh_rate - if it is not set, we need to set a default
if (undefined === data['refresh_rate'] || data['refresh_rate'] < minRefresh) {
data['refresh_rate'] = minRefresh * 2;
}

// look only at the tens place of the second counter to refresh cache every ten seconds.
timeStamp = time.substr(0, 2) + time.substr(3, 2) + time.substr(6, 1);

data.refresh_rate = getRefreshRate(data.refresh_rate || 0);

$.each(data, function (key, value) {
if (undefined !== callbacks[key] && (undefined === values[key] || values[key] !== value)) {
callbacks[key].fire(key, value); //pass key and value so that we can use the same callback for multiple keys
Expand All @@ -56,7 +60,7 @@
},
dataType: "json",
error : function () {
callbacks['refresh_rate'].fire('refresh_rate', minRefresh * ++errs);
callbacks['refresh_rate'].fire('refresh_rate', getRefreshRate() * ++errs);
}
});
}
Expand Down

0 comments on commit b0c813d

Please sign in to comment.