Fix a possible race condition when writing the backlog cache files