@bodar/totallylazy
Advanced tools
Comparing version
21
cache.js
@@ -7,10 +7,13 @@ "use strict"; | ||
throw new Error("@cache can only decorate methods"); | ||
const cache = {}; | ||
const cache = new Map(); | ||
return Object.defineProperty(target, name, Object.assign(Object.assign({}, descriptor), { value: function (...args) { | ||
const key = JSON.stringify(args); | ||
// @ts-ignore | ||
const result = cache[key]; | ||
const result = cache.get(key); | ||
if (typeof result !== 'undefined') | ||
return result; | ||
return cache[key] = descriptor.value.call(this, ...args); | ||
if (cache.has(key)) | ||
return result; | ||
const value = descriptor.value.call(this, ...args); | ||
cache.set(key, value); | ||
return value; | ||
} })); | ||
@@ -20,9 +23,13 @@ } | ||
function caching(fun) { | ||
const cache = {}; | ||
const cache = new Map(); | ||
return function (...args) { | ||
const key = JSON.stringify(args); | ||
const result = cache[key]; | ||
const result = cache.get(key); | ||
if (typeof result !== 'undefined') | ||
return result; | ||
return cache[key] = fun(...args); | ||
if (cache.has(key)) | ||
return result; | ||
const value = fun(...args); | ||
cache.set(key, value); | ||
return value; | ||
}; | ||
@@ -29,0 +36,0 @@ } |
@@ -783,4 +783,4 @@ "use strict"; | ||
"symbols": [ | ||
"₡", | ||
"Db" | ||
"Db", | ||
"₡" | ||
] | ||
@@ -787,0 +787,0 @@ }, |
{ | ||
"name": "@bodar/totallylazy", | ||
"version": "0.422.265", | ||
"version": "0.423.266", | ||
"description": "Totallylazy", | ||
@@ -5,0 +5,0 @@ "repository": "git@github.com:bodar/totallylazy.js.git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
429760
0.11%6267
0.11%