function handleCache(options, template) {
  var func;
  var filename = options.filename;
  var hasTemplate = arguments.length > 1;

  if (options.cache) {
    if (!filename) {
      throw new Error('cache option requires a filename');
    }
    func = exports.cache.get(filename);
    if (func) {
      return func;
    }
    if (!hasTemplate) {
      template = fileLoader(filename).toString().replace(_BOM, '');
    }
  }
  else if (!hasTemplate) {
    // istanbul ignore if: should not happen at all
    if (!filename) {
      throw new Error('Internal EJS error: no file name or template '
                    + 'provided');
    }
    template = fileLoader(filename).toString().replace(_BOM, '');
  }
  func = exports.compile(template, options);
  if (options.cache) {
    exports.cache.set(filename, func);
  }
  return func;
}
Get the template from a string or a file, either compiled on-the-fly or
read from cache (if enabled), and cache the template if needed.

If `template` is not set, the file specified in `options.filename` will be
read.

If `options.cache` is true, this function reads the file from
`options.filename` so it must be set prior to calling this function.

@memberof module:ejs-internal
@param {Options} options   compilation options
@param {String} [template] template source
@return {(TemplateFunction|ClientFunction)}
Depending on the value of `options.client`, either type might be returned.
@static