Skip to content

Instantly share code, notes, and snippets.

@JLevstein
Created October 25, 2013 19:03
Show Gist options
  • Save JLevstein/7160076 to your computer and use it in GitHub Desktop.
Save JLevstein/7160076 to your computer and use it in GitHub Desktop.
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