Last active
August 29, 2015 14:02
-
-
Save michaeljacobdavis/ee28a344da454092f5d7 to your computer and use it in GitHub Desktop.
Cache Service
This file contains 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
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