<commit_before>'use strict';

const uuid = require('node-uuid');
const _ = require('underscore');

const log = require("./logger");

var data = {};

module.exports = {

    /**
     * Prettry print all cache objects
     */
    debugAll: function(){
        log.debug("CACHE DEBUG:", JSON.stringify(data, undefined, 4));
    },

    /**
     * create - new cache object
     * @returns {*}
     */
    create: function create(id) {

        id = id || uuid.v1();

        if (_.has(data,id)===false){
            data[id] = { "remainingTasks": 0 };
            log.trace("Created new cacheId:",id);
        }

        return id;
    },

    /**
     * get - by cache id
     * @param id
     * @returns {*}
     */
    get: function get(id) {
        return data[id];
    },

    /**
     * addKey - to cache
     * @param id
     * @param key
     * @returns boolean
     */
    addKey: function addKey(id, key) {
        //increment count of expected responses
        data[id].remainingTasks ++;

        //create the key unless already created
        if (_.has(data[id],key)){
            log.trace("Cache returning false when adding new key \"" + key + "\" with id:", id);
            log.trace("CACHE DEBUG:", JSON.stringify(data, undefined, 4));
            return false;
        } else {
            data[id][key] = {};
            log.trace("Added new key \"" + key + "\" to cache:", id);
        }
        return true;
    },

    /**
     * add - add a key or the data for a key to the cache
     *
     * @param id  - string - cache id
     * @param key - string - the key to be used to store the
     *              data for each response payload.
     * @param cacheData - obj - the data to be cached
     * @returns {*} - obj - cache object
     */
    addData: function addData(id, key, cacheData) {
        log.trace("Adding data to cache. id, key:", id, key,  JSON.stringify(cacheData, undefined, 4));
        data[id][key] = cacheData || [];
        data[id].remainingTasks --;
        return data[id];
    }
};<commit_msg>Only log cache debug on "trace"<commit_after>'use strict';

const uuid = require('node-uuid');
const _ = require('underscore');

const log = require("./logger");

var data = {};

module.exports = {

    /**
     * Prettry print all cache objects
     */
    debugAll: function(){
        log.debug("CACHE DEBUG:", JSON.stringify(data, undefined, 4));
    },

    /**
     * create - new cache object
     * @returns {*}
     */
    create: function create(id) {

        id = id || uuid.v1();

        if (_.has(data,id)===false){
            data[id] = { "remainingTasks": 0 };
            log.debug("Created new cacheId:",id);
        }

        return id;
    },

    /**
     * get - by cache id
     * @param id
     * @returns {*}
     */
    get: function get(id) {
        return data[id];
    },

    /**
     * addKey - to cache
     * @param id
     * @param key
     * @returns boolean
     */
    addKey: function addKey(id, key) {
        //increment count of expected responses
        data[id].remainingTasks ++;

        //create the key unless already created
        if (_.has(data[id],key)){
            log.debug("Cache returning false when adding new key \"" + key + "\" with id:", id);
            log.debug("CACHE DEBUG:", JSON.stringify(data, undefined, 4));
            return false;
        } else {
            data[id][key] = {};
            log.debug("Added new key \"" + key + "\" to cache:", id);
        }
        return true;
    },

    /**
     * add - add a key or the data for a key to the cache
     *
     * @param id  - string - cache id
     * @param key - string - the key to be used to store the
     *              data for each response payload.
     * @param cacheData - obj - the data to be cached
     * @returns {*} - obj - cache object
     */
    addData: function addData(id, key, cacheData) {
        log.debug("Adding data to cache. id, key:", id, key,  JSON.stringify(cacheData, undefined, 4));
        data[id][key] = cacheData || [];
        data[id].remainingTasks --;
        return data[id];
    }
};
{'fraction_non_alphanumeric': 0.15009746588693956, 'fraction_numerical': 0.0024366471734892786, 'mean_word_length': 1.7849389416553596, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '5152509', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1213, 'n_words': 367}