<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_cache(cache, fobj, format=None):
 """Write a `list` of cache entries to a file Parameters cache : `list` of `str` The list of file paths to write fobj : `file`, `str` The open file object, or file path to write to. format : `str`, optional The format to write to, one of - `None` : format each entry using `str` - ``'lal'`` : write a LAL-format cache - ``'ffl'`` : write an FFL-format cache """

    # open file
    if isinstance(fobj, string_types):
        with open(fobj, 'w') as fobj2:
            return write_cache(cache, fobj2, format=format)

    if format is None:
        formatter = str
    elif format.lower() == "lal":
        formatter = _format_entry_lal
    elif format.lower() == "ffl":
        formatter = _format_entry_ffl
    else:
        raise ValueError("Unrecognised cache format {!r}".format(format))

    # write file
    for line in map(formatter, cache):
        try:
            print(line, file=fobj)
        except TypeError:  # bytes-mode
            fobj.write("{}\n".format(line).encode("utf-8"))