Added some time based cache bursting

This commit is contained in:
Martin Donnelly 2018-10-19 13:03:28 +01:00
parent e2440dcbbc
commit 5303b7f4de
5 changed files with 27 additions and 14 deletions

View File

@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
const CACHE_VERSION = { 'version': '0.0.910' };
const CACHE_VERSION = { 'version': '0.0.918' };
const PRECACHE = `jubileeData-${CACHE_VERSION.version}`;
const RUNTIME = 'runtime';
@ -124,15 +124,26 @@ self.addEventListener('fetch', event => {
);
}*/
/* if (event.request.url.startsWith(self.location.origin)) {
console.log('One of our requests..');
if (event.request.url.startsWith(self.location.origin)) {
console.log('!!', event.request);
event.respondWith(
/* event.respondWith(
caches.open(RUNTIME).then(function(cache) {
return cache.match(event.request).then(function (response) {
console.log('£', response);
return response || fetch(event.request).then(function(response) {
cache.put(event.request, response.clone());
return response;
});
});
})
);*/
event.respondWith(
caches.open(RUNTIME).then(function(cache) {
return cache.match(event.request).then(function (response) {
return response || fetch(event.request).then(function(response) {
cache.put(event.request, response.clone());
@ -141,7 +152,7 @@ self.addEventListener('fetch', event => {
});
})
);
}*/
}
if (event.request.url.startsWith('https://maps.googleapis.com')) {
const url = new URL(event.request.url);

View File

@ -4,7 +4,7 @@ const Backbone = require('backbone');
const request = require('request');
const { get } = require('lodash');
const { reduceNearby } = require('./libs/reducers');
const { toHour } = require('./libs/utils');
const { toHour, hourFloor } = require('./libs/utils');
const TimeFormat = require('hh-mm-ss');
const { FSDetailView } = require('./Foursquare');
@ -63,6 +63,7 @@ const NearbyModel = Backbone.Model.extend({
url.searchParams.append('ll', llFixed);
url.searchParams.append('section', section);
url.searchParams.append('w', hourFloor());
fetch(url)
.then(res => {

View File

@ -3,7 +3,7 @@ const _ = require('underscore');
const Backbone = require('backbone');
const request = require('request');
const { get, isEmpty } = require('lodash');
const { maybePluralize } = require('./libs/utils');
const { maybePluralize, hourFloor } = require('./libs/utils');
const templates = require('./libs/templates');
const ByMeModel = Backbone.Model.extend({

View File

@ -6,7 +6,7 @@ const fecha = require('fecha');
const TimeFormat = require('hh-mm-ss');
const { get } = require('lodash');
const { reduceOpenWeather } = require('./libs/reducers');
const { distance, toHour } = require('./libs/utils');
const { distance, toHour, hourFloor } = require('./libs/utils');
const WeatherAlertModel = Backbone.Model.extend({
'defaults': function (obj) {
@ -62,7 +62,8 @@ const WeatherAlertModel = Backbone.Model.extend({
'url': `${window.loc}/weatheralert`,
'method': 'GET',
'qs': {
'll': llFixed
'll': llFixed,
'w' : hourFloor()
}
}, function (err, res, body) {
console.log('statusCode', res.statusCode);
@ -118,7 +119,7 @@ const WeatherAlertView = Backbone.View.extend({
this.$title = $('#weatherAlertTitle');
// this.model.bind('change', this.render, this);
this.location.bind('change:llShort', this.updateLocation, this);
this.location.bind('change:llFixed', this.updateLocation, this);
this.model.bind('change:alert', this.render, this);
this.eventBus.on('focused', this.focused, this);
},
@ -143,8 +144,8 @@ const WeatherAlertView = Backbone.View.extend({
console.log('changedAttributes:', this.location.changedAttributes());
if (l.has('atHome')) {
const llShort = l.get('llShort');
this.model.set('ll', llShort);
const llFixed = l.get('llFixed');
this.model.set('ll', llFixed);
}
else
console.log('>> Weather No location yet');

View File

@ -51,7 +51,7 @@ function toHour(extra = 0) {
function hourFloor() {
const now = new Date();
return (~~(now.getTime() / 3600000) * 3600000);
return parseInt(~~(now.getTime() / 3600000) * 3600000, 10).toString(32);
}
function distance(lat1, lon1, lat2, lon2) {