SoFunction
Updated on 2025-04-08

nodejs read memcache example sharing


var memcache = require('memcache')
    , http = require('http')
    , url = require('url')
    , qs = require('querystring')
    , memsettings = { port: 2000, host: '10.6.0.6' }
    , httpsettings = { port: 3000 }
    , cacheObject = {}
    , httpserver
    , client
    , requestHandler;

client = new (, );
//...
('connect', function(){
     = true;
});

('close', function(){
    // no arguments - connection has been closed
     = false;
});

function getData(key, wrapper, res){
    (key, function(error, result){
            // all of the callbacks have two arguments.
            // 'result' may contain things which aren't great, but
            // aren't really errors, like 'NOT_STORED'
            if(!error){
                if(result){
                    cacheObject[key] = result;
                    ( wrapper + '(' + result + ')');
                } else {
                    ('no data');
                }
                ();
            }
     });
    /*if(cacheObject[key]){
        (cacheObject[key]);
        ();
    } else  {
        (key, function(error, result){

            // all of the callbacks have two arguments.
            // 'result' may contain things which aren't great, but
            // aren't really errors, like 'NOT_STORED'
            if(!error){
                cacheObject[key] = result;
                cacheObject[key]['timeoutId'] = setTimeout(function(){
                    (key, function(error, result){
                        if(!error){
                            cacheObject[key] = result;
                        }
                    });
                });
                (result);
                ();
            }
        });
    }*/
}

httpserver = (function(req, res){
    var urlObj, queryObj;
    urlObj = ();
    (200, {"Content-Type":"text/javascript; charset=utf-8"});
    queryObj = ();
    path = ;
    if(){
        getData(, ||'callback', res);
    } else {
        ('no input');
        ();
    }
    /*
    switch(){
        case '/pai':
            ();
        break;
        case '/qiang':
            ();
        break;
        default:
            ('default');
        break;
    }
    ();
    */
});

();
();
('http server listening on ' + );