Spaces:
Sleeping
Sleeping
File size: 639 Bytes
e4bf523 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 'use strict';
/**
* 아주 단순한 in-process handler cache.
* key = `${type}@@${path}`
* value = function(req) { ... }
*/
class HandlerCache {
constructor() {
this._map = new Map();
}
_key(type, path) {
return `${type}@@${path}`;
}
setCache(type, path, handler) {
if (typeof handler !== 'function') return;
this._map.set(this._key(type, path), handler);
}
getCache(type, path) {
return this._map.get(this._key(type, path)) || null;
}
removeCache(type, path) {
this._map.delete(this._key(type, path));
}
clear() {
this._map.clear();
}
}
module.exports = new HandlerCache();
|