{"size": 910, "ext": "js", "max_stars_repo_path": "lib/cache-engines/memcached.js", "max_stars_repo_name": "panzi/iframely", "max_stars_repo_stars_event_min_datetime": "2015-11-26T09:09:56.000Z", "max_stars_repo_stars_event_max_datetime": "2015-11-26T09:09:56.000Z", "max_issues_repo_path": "lib/cache-engines/memcached.js", "max_issues_repo_name": "panzi/iframely", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "lib/cache-engines/memcached.js", "max_forks_repo_name": "panzi/iframely", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.7647058824, "max_line_length": 98, "alphanum_fraction": 0.5175824176}
(function(engine) {

    var Memcached = require('memcached');
    var memcached = new Memcached(CONFIG.MEMCACHED_OPTIONS && CONFIG.MEMCACHED_OPTIONS.locations);

    engine.set = function(key, data) {
        // Warning: value and lifetime argumets switched, bug in docs.
        memcached.set(key, JSON.stringify(data), CONFIG.CACHE_TTL, function(error){
            if (error) {
                console.error('memcached set error', error);
            }
        });
    };

    engine.get = function(key, cb) {

        memcached.get(key, function (error, data) {

            if (error) {
                console.error('memcached get error', error);
                return cb(error);
            }

            try {
                var parsedData = JSON.parse(data);
            } catch(ex) {
                return cb(ex);
            }

            cb(null, parsedData);
        });
    };

})(exports);