<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def tempfile_writer(target):
    '''write cache data to a temporary location.  when writing is
    complete, rename the file to the actual location.  delete
    the temporary file on any error'''
    tmp = target.parent / ('_%s' % target.name)
    try:
        with tmp.open('wb') as fd:
            yield fd
    except:
        tmp.unlink()
        raise
    LOG.debug('rename %s -> %s', tmp, target)
    tmp.rename(target)