Created
October 25, 2013 19:03
-
-
Save JLevstein/7160076 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var app = angular.module('plunker', []); | |
app.controller('MainCtrl', function($scope, $http, $cacheFactory) { | |
// using $cacheFactory to make sure we clear | |
// the cache and then re-set it when cache is false | |
// in $scope.makeRequest | |
var httpCache = $cacheFactory.get('$http'); | |
$scope.makeRequest = function (cache) { | |
if(!cache) httpCache.remove('response.php'); | |
$http({ | |
method: 'GET', | |
cache: cache, | |
// obviously PHP doesn't work in Plnkr, | |
// but if you put this on a PHP server, | |
// the cache would flush itself | |
// as expected, and only get a new rand # | |
// if you click "Non-Cached Request" | |
url: 'response.php' | |
}).then(function(result) { | |
console.log('Got result: ', result.data); | |
if(!cache) httpCache.put('response.php', result.data); | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment