var cacheData = JSON.stringify(data);
this.getTwitterSearch(data, options);
cache.setex(query, cfg.cache.news.twitter, cacheData, function(){
c.log('set cache', query, cacheData);
});
如果我注释掉 this.getTwitterSearch
一切正常。怎么会这样?我不明白该函数如何使 cacheData
为空。
这是this.getTwitterSearch
:
News.prototype.getTwitterSearch = function getTwitterSearch(data, options){
var statuses = data.statuses
, items = [];
c.log('statuses', statuses);
_.each(statuses, function(d){
var item = this.getTwitterItem(query, d);
if ( item ) {
items.push(item);
}
}.bind(this));
//recent items since last poll
if ( options.since_id ) {
if ( items.length ) {
this.sock.emit('twitter:new', { items: items });
}
} else {
//initial payload
c.log('twitter:items', items.length);
if ( items.length ) {
this.sock.emit('twitter:items', { items: items });
}
}
c.log('items', items.length);
//TODO set cache items
//save the last id to use when fetching new items on next poll.
this.lastId = items.length && items[0].id || this.lastId;
};
最佳答案
我在 this.getTwitterItem(query, d);
中出错,它需要将 query
参数传递给它。否则,错误将被抛给 twit.search
回调,我将其作为数据读取,而不是错误。
关于javascript - 即使在 javascript 中保存了数据的副本,数据还是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20823092/