function measureAndCacheTextWidth(font, text, cache) {
  if (text in cache) {
    return cache[text];
  }
  const width = text
    .split('\n')
    .reduce((prev, curr) => Math.max(prev, measureTextWidth(font, curr)), 0);
  cache[text] = width;
  return width;
}
Measure text width using a cache.
@param {string} font The font.
@param {string} text The text to measure.
@param {Object<string, number>} cache A lookup of cached widths by text.
@return {number} The text width.