<commit_before>
function memCache() {
	this.cache = {};
}

memCache.prototype.has = function(req) {
	return typeof this.cache[this._hash(req)] != 'undefined';
}

memCache.prototype.send = function(req, res) {
	if (this.has(req)) {
		var data = this.cache[this._hash(req)].content;
		res.setResponseCode(this.cache[this._hash(req)].response_code);
		res.setContentType(this.cache[this._hash(req)].mime_type);
		res.setLastModified(this.getLastModified(req));
		res.setContent(data);
		res.send();
	}
}

memCache.prototype.getLastModified = function(req) {
	if (this.has(req)) {
		return (this.cache[this._hash(req)].time).toUTCString();
	} else {
		return false;
	}
}

memCache.prototype.validate = function (req) {
	var cached = this.cache[this._hash(req)] || false;
	if (this.has(req) && (cachedDate = (cached.time).getTime())) {

		for (var i = cached.dependencies.length - 1; i >= 0; i--) {
			try {
				if ((_fs.statSync(cached.dependencies[i]).mtime).getTime() > cachedDate) {
					return false;
				}
			} catch (e) {
				return false;
			}
		};
		return true;
	} else {
		return false;
	}
}

memCache.prototype.del = function (req) {
	if (this.has(req)) {
		console.log("Remove cache file: " + this._hash(req));
		this.cache[this._hash(req)] = undefined;
	}
}

memCache.prototype.clear = function() {
	this.cache = {};
}

memCache.prototype.add = function(req, cont, mime, code, dependsOn) {

	var data = {
		mime_type: mime,
		response_code: code,
		time: new Date(),
		dependencies: dependsOn,
		content: cont
	}
	console.log("Add mem cache " + this._hash(req));
	this.cache[this._hash(req)] = data;
}

memCache.prototype._hash = function(req) {
	var shasum = _crypto.createHash('sha1');
	shasum.update(req.url);
	return shasum.digest('hex');
}

exports.memCache = memCache;<commit_msg>make memCache a child of nullCache and use es6 class syntax<commit_after>var nullCache = require('./nullCache.js').nullCache;

class memCache extends nullCache {
	constructor() {
		super();
		this.cache = {};
	}

	has(req) {
		return typeof this.cache[this._hash(req)] != 'undefined';
	}

	send(req, res) {
		if (this.has(req)) {
			var data = this.cache[this._hash(req)].content;
			res.setResponseCode(this.cache[this._hash(req)].response_code);
			res.setContentType(this.cache[this._hash(req)].mime_type);
			res.setLastModified(this.getLastModified(req));
			res.setContent(data);
			res.send();
		}
	}

	getLastModified(req) {
		if (this.has(req)) {
			return (this.cache[this._hash(req)].time).toUTCString();
		} else {
			return false;
		}
	}

	validate(req) {
		var cached = this.cache[this._hash(req)] || false;
		if (this.has(req) && (cachedDate = (cached.time).getTime())) {z
			for (var i = cached.dependencies.length - 1; i >= 0; i--) {
				try {
					if ((_fs.statSync(cached.dependencies[i]).mtime).getTime() > cachedDate) {
						return false;
					}
				} catch (e) {
					return false;
				}
			};
			return true;
		} else {
			return false;
		}
	}

	del(req) {
		if (this.has(req)) {
			console.log("Remove cache file: " + this._hash(req));
			this.cache[this._hash(req)] = undefined;
		}
	}

	clear() {
		this.cache = {};
	}

	add(req, cont, mime, code, dependsOn) {
		var data = {
			mime_type: mime,
			response_code: code,
			time: new Date(),
			dependencies: dependsOn,
			content: cont
		}
		console.log("Add mem cache " + this._hash(req));
		this.cache[this._hash(req)] = data;
	}

	_hash(req) {
		return super._hash(req);
	}

}


exports.memCache = memCache;
{'fraction_non_alphanumeric': 0.1748994830557151, 'fraction_numerical': 0.0017231476163124641, 'mean_word_length': 3.668900804289544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5657488', 'n_tokens_mistral': 1426, 'n_tokens_neox': 1270, 'n_words': 232}