Skip to content

Instantly share code, notes, and snippets.

@michaeljacobdavis
Last active August 29, 2015 14:02
Show Gist options
  • Save michaeljacobdavis/ee28a344da454092f5d7 to your computer and use it in GitHub Desktop.
Save michaeljacobdavis/ee28a344da454092f5d7 to your computer and use it in GitHub Desktop.
Cache Service
function($http, $q) {
var cache = {};
return {
get: function (force){
var deferred = $q.defer();
if(force || !cache['get']){
return $http.get('/path/to/data').then(function(result){
return cache['get'] = result;
});
} else {
deferred.resolve(cache['get']);
return deferred.promise;
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment