我有下一个问题
我正在尝试使用 $http 缓存 get 请求,但似乎不起作用,缓存变量总是未定义
示例代码:
myApp.factory("sample", ["$http", "$q", "$cacheFactory", sample]);
function sample($http, $q, $cacheFactory) {
function getData() {
var url = "http://whatever ...";
return $http.get(url, {
params: {
Id: 10
},
cache: true
})
.then(function(response) {
// trying to get the cached data
var cache = $cacheFactory.get("$http");
var data = cache.get(url); // undefined -> ??
return response.data;
})
.catch(function(error) {
return $q.reject(error);
});
}
return {
getData: getData
};
}