我試圖使用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的結果是正確的。一旦它被放入緩存中,如何根據密鑰進行檢索。即'國家'。
修復了一些語法錯誤並增加了一些附加信息。 –