我试图使用memoize
功能从Underscore.js
Ajax调用缓存结果memoize的功能。我不确定我的执行情况。还有如何使用密钥取回缓存的结果数据。下面是我的实现:使用带有underscore.js
Javascript代码:
var cdata = $http
.get(HOST_URL + "/v1/report/states")
.success(function(data) {
//put the result in the angularJs scope object.
$scope.states = data;
});
//store the result in the cache.
var cachedResult = _.memoize(
function() {
return cdata;
}, "states");
是我的memoize的使用情况来存储AJAX的结果是正确的。一旦它被放入缓存中,如何根据密钥进行检索。即'国家'。
修复了一些语法错误并增加了一些附加信息。 –