'use strict';

const _defaultMemoizeResolver = first=>first;

function memoize(fn, resolver=_defaultMemoizeResolver) {
  function memoized(...params) {
    const lookupId = resolver(...params);
    if (memoized.cache.has(lookupId)) {
      const [err, data] = memoized.cache.get(lookupId);
      if (!err) return data;
      throw err;
    }

    try {
      const result = fn(...params);
      memoized.cache.set(lookupId, [null, result]);
      return result;
    } catch (err) {
      memoized.cache.set(lookupId, [err, undefined]);
      throw err;
    }
  }

  memoized.cache = new Map();
  return memoized;
}

function memoizeNode(fn, resolver=_defaultMemoizeResolver) {
  function memoized(...params) {
    const lookupId = resolver(...params);
    const cb = params.pop();
    if (memoized.cache.has(lookupId)) return cb(...memoized.cache.get(lookupId));
    return fn(...params, (...result)=>{
      memoized.cache.set(lookupId, result);
      return cb(...result);
    });
  }

  memoized.cache = new Map();
  return memoized;
}

function memoizePromise(fn, resolver=_defaultMemoizeResolver) {
  function memoized(...params) {
    const lookupId = resolver(...params);
    if (memoized.cache.has(lookupId)) {
      const [err, ...data] = memoized.cache.get(lookupId);
      if (!err) return Promise.reject(err);
      return Promise.resolve(((data.length > 1) ? data : data[0]));
    }

    return fn(...params).then((...data)=>{
      memoized.cache.set(lookupId, [null, ...data]);
      return ((data.length > 1) ? data : data[0]);
    }, err=>{
      memoized.cache.set(lookupId, [err]);
      return Promise.reject(err);
    });
  }

  memoized.cache = new Map();
  return memoized;
}

module.exports = {
  memoize, memoizeNode, memoizePromise
};
@@ -8,16 +8,30 @@
 rict';%0A%0A
+let settings%0A%0A
 const _d
@@ -65,14 +65,79 @@
 st=%3E
+%7B%0A  if (!settings) settings = require('./settings');%0A  return 
 first;
+%0A%7D;
 %0A%0Afu
@@ -216,32 +216,142 @@
 ed(...params) %7B%0A
+    if (!settings) settings = require('./settings');%0A    if (!settings.get('useCache')) return fn(...params);%0A
     const lookup
@@ -884,32 +884,171 @@
 ed(...params) %7B%0A
+    if (!settings) settings = require('./settings');%0A    if (!settings.get('useCache')) return fn(...params);%0A    const cb = params.pop();%0A
     const lookup
@@ -1077,37 +1077,8 @@
 s);%0A
-    const cb = params.pop();%0A
     
@@ -1425,24 +1425,134 @@
 ..params) %7B%0A
+    if (!settings) settings = require('./settings');%0A    if (!settings.get('useCache')) return fn(...params);%0A
     const lo

Put cache behind the option useCache