Calling http.get to same file doesn't work correctly


#1

I’m building an Android app that uses the Google Maps api and markers that update position based on a json file grabbed from a server. So, in a controller, I do this:

var bargeFile = 'https://press-street.org/ybh/barge.json';
var bargeMarker = new google.maps.Marker();
$scope.generateBargeMarker = function() {
    $http.get(bargeFile, {cache: false}).success( function(data) {
        var gps = data["gps"];
        bargeMarker.setPosition(new google.maps.LatLng(gps[0], gps[1]));
        bargeMarker.setMap(map);
    });
};

$scope.generateBargeMarker();
$interval($scope.generateBargeMarker, 6000);

The marker shows up, and the get is definitely succeeding every time, but it must be saving the first value and continuing to use that. The only way to reset it and have it read the new value (after I change values in the file on the server), is to clear the app data in app settings. Also, every time I switch to another view, then back to the map, the total app data increases by some 0.02 mb, which I infer is the files being grabbed, saved, and then not used.

How can I resolve this to have the $http.get call actually use the requested file each time, by I guess having it overwrite the existing saved version or something, or not saving it at all?


#2

So you’re caching something that shouldn’t be cached? Perhaps you could look at the server configuration. If that doesn’t work, you could add a small random GET parameter that changes whenever you want to force an update.

What files? How do you know?


#3

I know by looking in android app settings, whenever I switch views from then back to the map it tells me that there’s 0.02mb more data for the app.

I wouldn’t think that it could be that, because I have had it update correctly in browser.