From 82708124068218cd51069891afba4f56d535433c Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Fri, 25 Oct 2013 07:10:35 +0100 Subject: [PATCH] experimental change: render stale map data tiles before downloading fresh data - should give a more responsive appearance of data also increase cache expiry time to 15 mins --- code/map_data_cache.js | 2 +- code/map_data_request.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/code/map_data_cache.js b/code/map_data_cache.js index bdd18228..a04070fc 100644 --- a/code/map_data_cache.js +++ b/code/map_data_cache.js @@ -11,7 +11,7 @@ window.DataCache = function() { // entries would grow indefinitely. an hour seems reasonable from experience with the data, so 55 mins max cache time // this.REQUEST_CACHE_MAX_AGE = 55*60; // maximum cache age. entries are deleted from the cache after this time //UPDATE: this timestampMs parameter doesn't work, so reduced max age to limit RAM usage - this.REQUEST_CACHE_MAX_AGE = 5*60; // maximum cache age. entries are deleted from the cache after this time + this.REQUEST_CACHE_MAX_AGE = 15*60; // maximum cache age. entries are deleted from the cache after this time if (L.Browser.mobile) { // on mobile devices, smaller cache size diff --git a/code/map_data_request.js b/code/map_data_request.js index c118d23f..5e49a3f8 100644 --- a/code/map_data_request.js +++ b/code/map_data_request.js @@ -247,7 +247,15 @@ window.MapDataRequest.prototype.refresh = function() { this.cachedTileCount += 1; } else { - // no fresh data - queue a request + // no fresh data + + // render the cached stale data, if we have it. this ensures *something* appears quickly when possible + var old_data = this.cache && this.cache.get(tile_id); + if (old_data) { + this.render.processTileData (old_data); + } + + // queue a request var boundsParams = generateBoundsParams( tile_id, latSouth,