<commit_before>var Promise = global.Packages.Promise;

var _cacheClient, _defaultExpiryInSeconds = 60 * 60;

var getCacheClient = function(ctx) {

    var needstoreload = false;

    if (!_cacheClient) {
        needstoreload = true;
    }

    if (needstoreload) {

        return ctx.getServers().then(function(servers) {

            if (_cacheClient) {
                return _cacheClient;
            }

            var mongodb_client = require("../models/mongo").initialize({

                host: servers[0].server,
                port: servers[0].port,
                db: "cachedb"
            });

            _cacheClient = mongodb_client.extend({
                tableName: "cache"
            });

            _cacheClient.prototype.getDBObject = function getDBObject(object) {

                // prepare mongo specific object from user given object
                return {
                    _id: object.key,
                    value: object.value,
                    modified_on: object.modified_on
                };
            };

            _cacheClient.prototype.getObjectFromDBObject = function getObjectFromDBObject(mongoObject) {
                // return userfriends specific object from mongo object
                mongoObject.key = mongoObject._id;
                delete mongoObject._id;
                return mongoObject;
            };


            return _cacheClient;

        });
    }
    else {
        return new Promise(function(resolve) {
            resolve(_cacheClient);
            return;
        });
    }
};

function MongoDBCache() {

}

MongoDBCache.prototype.getServers = function getServers() {
    return new Promise(function(resolve) {
        return resolve([{
            server: "localhost",
            port: 27017
        }]);
    });
};

function setValue(Mongo_client, key, value, expiry_in_seconds) {
    // not sure currently that how we handle expiry so currently setting it to zero 
    expiry_in_seconds = 0;
    return new Mongo_client({
        key: key,
        value: value
    }).save().then(function() {
        return;
    });

}

function getValue(Mongo_client, key) {
    return new Mongo_client({
        key: key
    }).fetch().then(function(obj) {
        if (obj) {
            return obj.value;
        }
        else {
            return null;
        }
    });
}

function removeValue(Mongo_client, key) {
    return new Mongo_client({
        key: key
    }).deleteObject().then(function() {
        return;
    });
}

MongoDBCache.prototype.set = function set(key, value, expiry_in_seconds) {
    var self = this;
    expiry_in_seconds = (expiry_in_seconds && expiry_in_seconds > 0) ? expiry_in_seconds : _defaultExpiryInSeconds;
    return getCacheClient(self).then(function(cache) {

        return setValue(cache, key, value, expiry_in_seconds).then(function() {
            return;
        });

    }).then(function() {
        return;
    });
};

MongoDBCache.prototype.get = function get(key) {
    var self = this;
    return getCacheClient(self).then(function(cache) {

        return getValue(cache, key).then(function(value) {
            return value;
        });

    });

};<commit_msg>removed unnecessary code from mongodb cache<commit_after>var Promise = global.Packages.Promise;

var _cacheClient, _defaultExpiryInSeconds = 60 * 60;

var getCacheClient = function(ctx) {

    var needstoreload = false;

    if (!_cacheClient) {
        needstoreload = true;
    }

    if (needstoreload) {

        return ctx.getServers().then(function(servers) {

            if (_cacheClient) {
                return _cacheClient;
            }

            var mongodb_client = require("../models/mongo").initialize({

                host: servers[0].server,
                port: servers[0].port,
                db: "cachedb"
            });

            _cacheClient = mongodb_client.extend({
                tableName: "cache"
            });

            return _cacheClient;

        });
    }
    else {
        return new Promise(function(resolve) {
            resolve(_cacheClient);
            return;
        });
    }
};

function MongoDBCache() {

}

MongoDBCache.prototype.getServers = function getServers() {
    return new Promise(function(resolve) {
        return resolve([{
            server: "localhost",
            port: 27017
        }]);
    });
};

function setValue(Mongo_client, key, value, expiry_in_seconds) {
    // not sure currently that how we handle expiry so currently setting it to zero 
    expiry_in_seconds = 0;
    return new Mongo_client({
        _id: key,
        value: value
    }).save().then(function() {
        return;
    });

}

function getValue(Mongo_client, key) {
    return new Mongo_client({
        _id : key
    }).fetch().then(function(obj) {
        if (obj) {
            return obj.value;
        }
        else {
            return null;
        }
    });
}

function removeValue(Mongo_client, key) {
    return new Mongo_client({
        _id: key
    }).deleteObject().then(function() {
        return;
    });
}

MongoDBCache.prototype.set = function set(key, value, expiry_in_seconds) {
    var self = this;
    expiry_in_seconds = (expiry_in_seconds && expiry_in_seconds > 0) ? expiry_in_seconds : _defaultExpiryInSeconds;
    return getCacheClient(self).then(function(cache) {

        return setValue(cache, key, value, expiry_in_seconds).then(function() {
            return;
        });

    }).then(function() {
        return;
    });
};

MongoDBCache.prototype.get = function get(key) {
    var self = this;
    return getCacheClient(self).then(function(cache) {

        return getValue(cache, key).then(function(value) {
            return value;
        });

    });

};
{'fraction_non_alphanumeric': 0.10962241169305725, 'fraction_numerical': 0.004524099530189664, 'mean_word_length': 1.9416581371545547, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5495963', 'n_tokens_mistral': 1719, 'n_tokens_neox': 1623, 'n_words': 347}