function createCache() {
  let cache = {
    byString: {},
    byReference: {
      keys: [],
      values: []
    }
  };
  return {
    put: function(key, value) {
      if (typeof key === 'object') {
        const index = cache.byReference.keys.indexOf(key);
        if (index === -1) {
          cache.byReference.keys.push(key);
          cache.byReference.values.push(value);
        } else {
          cache.byReference.values[index] = value;
        }
      } else {
        cache.byString[key] = value;
      }
    },
    get: function(key) {
      if (!key) {
        return cache;
      } else if (typeof key === 'object') {
        const index = cache.byReference.keys.indexOf(key);
        return cache.byReference.values[index];
      } else {
        return cache.byString[key];
      }
    }
  };
}
// Returns a cache object where key can be string or object/function reference
Returns a cache object where key can be string or object/function reference
Returns a cache object where key can be string or object / function reference
function createCache() {
  let cache = {
    byString: {},
    byReference: {
      keys: [],
      values: []
    }
  };
  return {
    put: function(key, value) {
      if (typeof key === 'object') {
        const index = cache.byReference.keys.indexOf(key);
        if (index === -1) {
          cache.byReference.keys.push(key);
          cache.byReference.values.push(value);
        } else {
          cache.byReference.values[index] = value;
        }
      } else {
        cache.byString[key] = value;
      }
    },
    get: function(key) {
      if (!key) {
        return cache;
      } else if (typeof key === 'object') {
        const index = cache.byReference.keys.indexOf(key);
        return cache.byReference.values[index];
      } else {
        return cache.byString[key];
      }
    }
  };
}
function createCache ( ) { let cache = { byString : { } , byReference : { keys : [ ] , values : [ ] } } ; return { put : function ( key , value ) { if ( typeof key === 'object' ) { const index = cache . byReference . keys . indexOf ( key ) ; if ( index === - 1 ) { cache . byReference . keys . push ( key ) ; cache . byReference . values . push ( value ) ; } else { cache . byReference . values [ index ] = value ; } } else { cache . byString [ key ] = value ; } } , get : function ( key ) { if ( ! key ) { return cache ; } else if ( typeof key === 'object' ) { const index = cache . byReference . keys . indexOf ( key ) ; return cache . byReference . values [ index ] ; } else { return cache . byString [ key ] ; } } } ; }
Returns a cache object where key can be string or object/function reference
Returns a cache object where key can be string or object / function reference