'Actually write the file to the cache directory, return its size.
If filesystem block size is known, try to return actual disk space used.'

def _write(self, body, path, format):

    fullpath = pathjoin(self.cachepath, path)
    try:
        umask_old = os.umask(self.umask)
        os.makedirs(dirname(fullpath), (511 & (~ self.umask)))
    except OSError as e:
        if (e.errno != 17):
            raise
    finally:
        os.umask(umask_old)
    (fh, tmp_path) = mkstemp(dir=self.cachepath, suffix=('.' + format.lower()))
    os.write(fh, body)
    os.close(fh)
    try:
        os.rename(tmp_path, fullpath)
    except OSError:
        os.unlink(fullpath)
        os.rename(tmp_path, fullpath)
    os.chmod(fullpath, (438 & (~ self.umask)))
    stat = os.stat(fullpath)
    size = stat.st_size
    if hasattr(stat, 'st_blksize'):
        blocks = _ceil((size / float(stat.st_blksize)))
        size = int((blocks * stat.st_blksize))
    return size
