def write_credentials(self, credentials=None, profile=None,<EOL>cache_token=None):
d = {<EOL>'<STR_LIT>': profile,<EOL>'<STR_LIT>': credentials.client_id,<EOL>'<STR_LIT>': credentials.client_secret,<EOL>'<STR_LIT>': credentials.refresh_token<EOL>}<EOL>if cache_token:<EOL><INDENT>d.update({'<STR_LIT>': credentials.access_token})<EOL><DEDENT>with self.lock:<EOL><INDENT>return self.db.upsert(<EOL>d, self.query.profile == profile<EOL>)<EOL><DEDENT>
Write credentials.

        Write credentials to credentials file. Performs ``upsert``.

        Args:
            cache_token (bool): If ``True``, stores ``access_token`` in token store. Defaults to ``True``.
            credentials (class): Read-only credentials.
            profile (str): Credentials profile. Defaults to ``'default'``.

        Returns:
            int: Affected document ID.