<commit_before>var debug = require('debug')('carcass:Storage:Memory');

var carcass = require('carcass');
var _ = require('underscore');

var noop = function() {};

module.exports = carcass.factories.Storage({
    title: 'Memory',
    cache: 'memory',
    initialize: initialize
});

function initialize(instance, options) {
    debug('initializing');

    var store = instance.store = {};

    // Create or Update.
    // Requires data.
    instance.put = function(data, callback) {
        debug('saving');
        callback = callback || noop;
        var id = data._id || data.id || _.uniqueId();
        store[id] = data;
        data._id = id;
        callback(null, data);
    };<commit_msg>Improved memory storage: stores a clone.<commit_after>var debug = require('debug')('carcass:Storage:Memory');

var carcass = require('carcass');
var _ = require('underscore');

var noop = function() {};

module.exports = carcass.factories.Storage({
    title: 'Memory',
    cache: 'memory',
    initialize: initialize
});

function initialize(instance, options) {
    debug('initializing');

    var store = instance.store = {};

    // Create or Update.
    // Requires data.
    instance.put = function(data, callback) {
        debug('saving');
        callback = callback || noop;
        var id = data._id || data.id || _.uniqueId();
        var doc = store[id] = _.clone(data);
        doc._id = id;
        callback(null, doc);
    };
{'fraction_non_alphanumeric': 0.15855354659248957, 'fraction_numerical': 0.0, 'mean_word_length': 2.9424657534246577, 'pattern_counts': {'":': 0, '<': 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': '6770859', 'n_tokens_mistral': 433, 'n_tokens_neox': 419, 'n_words': 105}