mirror of
https://github.com/BreizhHardware/memoizee.git
synced 2026-01-18 16:37:21 +01:00
- Move out main modules from `lib` folder - Introduce `normalizer` based configurations, and convert primitive and regular handlers into thos normalizers (can be found in lib/normalizers folder). Custom normalizers can be provided at run time via `normaizer` option - Provide `plain` module which does not load any extensions or normalizers. Any extensions that have to be used should be required upfront and normalizers should be provided directly - Remove `method` option, instead `methods` and `methods-plan` modules are provided which generate descriptors for lazy created memoized methods - `profile` is no longer extension. To be used it should be required directly - Improve logic for `async` handling - Take out `max` extensionLRU logic into external `lru-queue` package - Remove `context` option - Remove possibility to access original arguments when resolvers are used - Assure expected length of memoized functions
31 lines
615 B
JavaScript
31 lines
615 B
JavaScript
'use strict';
|
|
|
|
var indexOf = require('es5-ext/array/#/e-index-of');
|
|
|
|
module.exports = function () {
|
|
var lastId = 0, argsMap = [], cache = [];
|
|
return {
|
|
get: function (args) {
|
|
var index = indexOf.call(argsMap, args[0]);
|
|
return (index === -1) ? null : cache[index];
|
|
},
|
|
set: function (args) {
|
|
argsMap.push(args[0]);
|
|
cache.push(++lastId);
|
|
return lastId;
|
|
},
|
|
delete: function (id) {
|
|
var index = indexOf.call(cache, id);
|
|
if (index !== -1) {
|
|
argsMap.splice(index, 1);
|
|
cache.splice(index, 1);
|
|
}
|
|
},
|
|
clear: function () {
|
|
argsMap = [];
|
|
cache = [];
|
|
lastId = 0;
|
|
}
|
|
};
|
|
};
|