text: var $modelCreated = require("./../internal/model-created");
  var isInternalKey = require("./../support/isInternalKey");
  
  /**
   * decends and copies the cache.
   */
  module.exports = function getCache(cache) {
      var out = {};
      _copyCache(cache, out);
  
      return out;
  };
  
  function cloneBoxedValue(boxedValue) {
      var clonedValue = {};
  
      var keys = Object.keys(boxedValue);
      var key;
      var i;
      var l;
  
      for (i = 0, l = keys.length; i < l; i++) {
          key = keys[i];
  
          if (!isInternalKey(key)) {
              clonedValue[key] = boxedValue[key];
          }
      }
  
      return clonedValue;
  }
  
  function _copyCache(node, out, fromKey) {
      // copy and return
  
      Object.
          keys(node).
          filter(function(k) {
              // Its not an internal key and the node has a value.  In the cache
              // there are 3 possibilities for values.
              // 1: A branch node.
              // 2: A $type-value node.
              // 3: undefined
              // We will strip out 3
              return !isInternalKey(k) && node[k];
          }).
          forEach(function(key) {
              var cacheNext = node[key];
              var outNext = out[key];
  
              if (!outNext) {
                  outNext = out[key] = {};
              }
  
              // Paste the node into the out cache.
              if (cacheNext.$type) {
                  var isObject = cacheNext.value && typeof cacheNext.value === "object";
                  var isUserCreatedcacheNext = !node[$modelCreated];
                  var value;
                  if (isObject || isUserCreatedcacheNext) {
                      value = cloneBoxedValue(cacheNext);
                  } else {
                      value = cacheNext.value;
                  }
  
                  out[key] = value;
                  return;
              }
  
              _copyCache(cacheNext, outNext, key);
          });
  }
  