var memcache = require('memcache')
, http = require('http')
, url = require('url')
, url = require('url')
, url = require('url')
, url = require('url')
)
, memsettings = { 連接埠: 2000, 主機: '10.6.0.6' }
, httpsettings = {Object: 3000 } , requestHandler;
client = new memcache.Client(memsettings.port, memsettings.host);
//...
client.on('connect', ftionunc() {
client.connected = true;
});
client.on('close', function(){
connected = false;
});
function getData(key,wrapper,res){
client.get(key,function(error, 兩個參數。 if(!error){
if(結果){
cacheObject[key] = result;
🎜> } else {
🎜> }
});
/*if(cacheObject[key]){
res ponse.write(cacheObject[key]);
response.end();
} else {
// 所有回呼都有兩個參數。
// 'result' 可能包含不太好的內容,但是
/// 上真正的錯誤,例如'NOT_STORED' cacheObject[key]['timeoutId'] = setTimeout(function(){
ult){
if(!error){
cacheObject[有效性] = 結果;
}
});
所 🎜> }
});
}*/
}
httpserver = http.createServer(function(req, res){
var urlObj, queryObj;
urlObj = .url.parIf.url {"Content-Type":"text/javascript; charset=utf-8"});
queryObj = qs.parse(urlObj.query);
路徑) ) .gid){
getData(queryObj.gid, queryObj.callback||'callback', res);
res . end ();
}
/*
switch(urlObj.name){
res.write(urlObj.pathname);
break;
case '/qiang':
res.write(urlObj.pathname); res.write('default');
休息;
}
res.end();
*/
});
client.connect();
httpserver.listen(httpsettings.port);