3
我正在使用Request-Promise(請參閱下面的代碼)。請求 - 承諾:確保緩存結果
問題:如果我緩存一個承諾,是否緩存結果或每次要求一個新的?
例子:
var cachedPromise = getTokenPromise();
cachedPromise.then(function(authorizationToken1) {
//...
});
cachedPromise.then(function(authorizationToken2) {
//...
});
//QUESTION: Is right that authorizationToken1 equals authorizationToken2
getTokenPromise()函數:
var querystring = require('querystring');
var rp = require('request-promise');
/**
* Returns an authorization token promise
*/
function getTokenPromise() {
var requestOpts = {
encoding: 'utf8',
uri: 'https://datamarket.accesscontrol.windows.net/v2/OAuth2-13',
method: 'POST',
body: querystring.stringify({
'client_id': 'Subtitles',
'client_secret': 'Xv.............................s=',
'scope': 'http://api.microsofttranslator.com',
'grant_type': 'client_credentials'
})
};
return rp(requestOpts);
}